I did my widget...its working well..i mean..i get all category and sub category..
now the problem its that i get "Undefined index" for categoryIds variable..
how can i pass a variable from inside a widget to the actionCreat function...?
thank you so much...this its the code:
WIDGET CLASS:
class TutteCategorie extends CWidget { private $_parent; public function init() { $this->_parent = Category::model()->findAll('parent_id = 0'); } public function getTutteCategorie() { return $this->_parent; } public function run() { // this method is called by CController::endWidget() $this->render('tutteCategorie'); } }
WIDGET VIEW
foreach($this->getTutteCategorie() as $parent): { $child= $parent->getChilds(); //var_dump($child); echo $parent->nome ; echo "<br />"; echo CHtml::activeCheckBoxList( $parent, 'categoryIds', $parents = Chtml::listData(Category::model()->findAll('parent_id = :id',array(':id'=> $parent->id)),'id','nome') ); } endforeach;
PostController
if($model->save()) foreach ($_POST['Post']['categoryIds'] as $categoryId) { $postCategory = new PostCategory; $postCategory->post_id = $model->id; $postCategory->category_id = $categoryId; if (!$postCategory->save()) print_r($postCategory->errors); } $this->redirect(array('view','id'=>$model->id)); }
this is my form view HTML
<div class="row"> Category 1 <input type="hidden" name="Category[categoryIds]" value="" id="ytCategory_categoryIds"> <span id="Category_categoryIds"> <input type="checkbox" name="Category[categoryIds][]" value="1" id="Category_categoryIds_0"> <label for="Category_categoryIds_0">Cat1 - Sub-Category 1</label> <input type="checkbox" name="Category[categoryIds][]" value="2" id="Category_categoryIds_1"> <label for="Category_categoryIds_1">Cat1 - Sub-Category 2</label> <input type="checkbox" name="Category[categoryIds][]" value="3" id="Category_categoryIds_2"> <label for="Category_categoryIds_2">Cat1 - Sub-Category 3</label> <input type="checkbox" name="Category[categoryIds][]" value="4" id="Category_categoryIds_3"> <label for="Category_categoryIds_3">Cat1 - Sub-Category 4</label></span> Category 2 <input type="hidden" name="Category[categoryIds]" value="" id="ytCategory_categoryIds"> <span id="Category_categoryIds"> <input type="checkbox" name="Category[categoryIds][]" value="7" id="Category_categoryIds_0"> <label for="Category_categoryIds_0">Cat2 - Sub-Category 1</label> <input type="checkbox" name="Category[categoryIds][]" value="8" id="Category_categoryIds_1"> <label for="Category_categoryIds_1">Cat2 - Sub-Category 2</label> <input type="checkbox" name="Category[categoryIds][]" value="9" id="Category_categoryIds_2"> <label for="Category_categoryIds_2">Cat2 - Sub-Category 3</label> </span> </div>
i want to save in the post_categories junction table the values stored in the sub categories field....
thank you all!!

