Hello, i have form whitch on post I insert the data into Mongo, and then bring back the inserted data on the form(in case to edit) + id of document.If try to make edit on same form after first insert mongo save() return true, but the data stays the same and never goes updated. Controller :
public function editHotelAction($propertySupplierId, $sellingCode)
{
$this->property_supplier_id = $propertySupplierId;
$form = new EditHotelForm();
if (empty($this->request->getPost('documentId'))) {
$form->initialize(json_decode(json_encode($this->getExportedData())), $sellingCode);
}
if ($this->request->isPost()) {
if (empty($this->request->getPost('documentId'))) {
$hotelsModel = new Hotels();
} else {
$hotelsModel = Hotels::findById($this->request->getPost('documentId'));
}
$this->setCollections();
$hotelsModel->setInfo($this->getCollection('infoCollection'))
->setBrochure($this->getCollection('brochureCollection'))
->setSupplier($this->getCollection('supplierCollection'))
->sellingCode = $this->request->getPost('sellingCode');
if ($hotelsModel->save()) {
//Load the Updated Hotel, not original content
$form->initialize(json_decode(json_encode($hotelsModel)), $sellingCode);
$this->flashSession->success('Successfully edit Hotel!');
foreach ($hotelsModel->_id as $id) {
$this->view->documentId = $id;
}
} else {
$this->getErrors($hotelsModel);
}
}
$this->view->form = $form;
}
Model :
namespace Modules\Agent\Models;
class Hotels extends \Phalcon\Mvc\Collection
{
/**
* Collection
* @var
*/
public $info;
/**
* Collection
* @var
*/
public $brochure;
/**
* Collection
* @var
*/
public $supplier;
public function getCollection()
{
return $this->getConnection()->selectCollection('broadway_content');
}
/**
* @return mixed
*/
public function getInfo()
{
return $this->info;
}
/**
* @param mixed $info
*/
public function setInfo(array $info)
{
foreach ($info as $key => $value) {
$this->info->$key = $value;
}
return $this;
}
/**
* @return mixed
*/
public function getBrochure()
{
return $this->brochure;
}
/**
* @param mixed $brochure
*/
public function setBrochure(array $brochure)
{
foreach ($brochure as $key => $value) {
$this->brochure->$key = $value;
}
return $this;
}
/**
* @return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
/**
* @param mixed $supplier
*/
public function setSupplier(array $supplier)
{
foreach ($supplier as $key => $value) {
$this->supplier->$key = $value;
}
return $this;
}
}
View:
<?php $this->partial('base/_messages') ?>
<div class="row">
<div class="col-sm-12">
<form class="form-horizontal" role="form" method="POST">
<div class="form-group">
<label for="hotelName" class="col-sm-2 control-label">Hotel name</label>
<div class="col-sm-4">
<?php echo $form->render('hotelName'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="countryName">Country name</label>
<div class="col-sm-4">
<?php echo $form->render('countryName'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="countryCode">Country code</label>
<div class="col-sm-4">
<?php echo $form->render('countryCode'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="resortName">Resort name</label>
<div class="col-sm-4">
<?php echo $form->render('resortName'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="email">Email</label>
<div class="col-sm-4">
<?php echo $form->render('email'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="phone">Phone</label>
<div class="col-sm-4">
<?php echo $form->render('phone'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="rooms">Rooms</label>
<div class="col-sm-4">
<?php echo $form->render('rooms'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="brochureName">Brochure name</label>
<div class="col-sm-4">
<?php echo $form->render('brochureName'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="startDate">Start date</label>
<div class="col-sm-4">
<?php echo $form->render('startDate'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="endDate">End date</label>
<div class="col-sm-4">
<?php echo $form->render('endDate'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="supplierName">Supplier name</label>
<div class="col-sm-4">
<?php echo $form->render('supplierName'); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="supplierCode">Supplier code</label>
<div class="col-sm-4">
<?php echo $form->render('supplierCode'); ?>
</div>
</div>
<div class="form-group" style="margin-left: 470px;">
<?php echo $form->render('sellingCode');
if ($documentId) { ?>
<input type="hidden" value="<?php echo $documentId ?>" name="documentId">
<?php } ?>
<div class="col-sm-4">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</form>
</div>
</div>