The problem I am facing is with multiple models in one controller / view in Yii. In particular, I cannot figure out how to create a search bar for my related model in the admin view and search using the generated Gii CRUD.
I have two models: Recipes and Recipes
This is my recipe relationship.
public function relations() {
I can already create and update using related models, the problem arises under the search. I see the associated RecipeSteps model in the results because I added it to my Gridview as follows:
<?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'recipes-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array(
However, I need to figure out how to add โinstructionsโ in the search bar above the field so that I can search for the file as well.
I need to figure out how to add โinstructionsโ to my form.
<div class="wide form"> <?php $form=$this->beginWidget('CActiveForm', array( 'action'=>Yii::app()->createUrl($this->route), 'method'=>'get', )); ?> <div class="row"> <?php echo $form->label($model,'recipe_name'); ?> <?php echo $form->textField($model,'recipe_name',array('size'=>11,'maxlength'=>11)); ?> </div> <div class="row"> <?php echo $form->label($model,'recipe_description'); ?> <?php echo $form->textArea($model,'recipe_description',array('rows'=>6, 'cols'=>50)); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton('Search'); ?> </div> <?php $this->endWidget(); ?> </div>
Recipe search function in recipes
public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; //$criteria->compare('recipe_id',$this->recipe_id,true); $criteria->compare('recipe_name',$this->recipe_name,true); $criteria->compare('recipe_description',$this->recipe_description,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, ));
in both Index and Admin in RecipesController
public function actionIndex() { $dataProvider=new CActiveDataProvider('Recipes'); $this->render('index',array( 'dataProvider'=>$dataProvider, )); } public function actionAdmin() { $model=new Recipes('search'); $model->unsetAttributes();
I know this should be easy, but I can't figure out how to hug him around. I read every piece of documentation I could find.