2.Error: After saving the listing there is no ability to uncheck the references 'Security', 'Comfort', 'Kitchen' etc.
Put the protected\modules\apartments\models\Apartment.php, method public function saveCategories() file out of the condition 'if(isset($_POST['category']))'
- Code: Select all
$sql = 'DELETE FROM {{apartment_reference}} WHERE apartment_id="'.$this->id.'"';
Yii::app()->db->createCommand($sql)->execute();
So you will have as a result:
- Code: Select all
public function saveCategories(){
$sql = 'DELETE FROM {{apartment_reference}} WHERE apartment_id="'.$this->id.'"';
Yii::app()->db->createCommand($sql)->execute();
if(isset($_POST['category'])){
foreach($_POST['category'] as $catId => $value){
foreach($value as $valId => $val){
$sql = 'INSERT INTO {{apartment_reference}} (reference_id, reference_value_id, apartment_id)
VALUES (:refId, :refValId, :apId) ';
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":refId", $catId, PDO::PARAM_INT);
$command->bindValue(":refValId", $valId, PDO::PARAM_INT);
$command->bindValue(":apId", $this->id, PDO::PARAM_INT);
$command->execute();
}
}
}
}