Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:57:42+00:00 2026-05-29T15:57:42+00:00

The issue I’m having is related to multiple models in a single controller/view in

  • 0

The issue I’m having is related to multiple models in a single controller/view in Yii.
Specifically I can’t figure out how to have a search bar for my related model in the the admin and search views with Gii generated CRUD.

I have two models “Recipes” and “RecipeSteps”

This is my Recipes relations

public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        'recipeSteps' => array(self::HAS_ONE, 'RecipeSteps', 'recipe_id'),
        );
    }

I can already create and update using the related models the issue comes in under the search I can see the related model “RecipeSteps” in the results because I added it into my Gridview like so:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'recipes-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        //'recipe_id',
        'recipe_name',
        'recipe_description',
        'recipeSteps.instructions',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

However I need to figure out how to add in the search bar above the “instructions” field so that filed can be searched 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><!-- search-form -->

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,
        ));

and in Index and Admin in RecipesController

/**
 * Lists all models.
 */
public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('Recipes');
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

/**
 * Manages all models.
 */
public function actionAdmin()
{
    $model=new Recipes('search');
    $model->unsetAttributes();  // clear any default values
    if(isset($_GET['Recipes']))
        $model->attributes=$_GET['Recipes'];

    $this->render('admin',array(
        'model'=>$model,
    ));
}

I know this should be easy but I can’t seem to figure out how to wrap my head around it I have read every piece of documentation I could find.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:57:44+00:00Added an answer on May 29, 2026 at 3:57 pm

    You need to alter your search and column definition to work with the relation.
    You need to use with(), columns filter().

    Read this topic:

    Yii – Search filter of a relations field through cgridview

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Issue: I have a standard subclassed NSManagedObject (see below). I have a view controller
Issue : What is the best way to have a comprehensive view of birth/death/mem
The issue I'm having is my wsgi file can't import the wsgi handlers properly.
This issue is driving me mad. I have several tables defined, and CRUD stored
The issue I have is as follows: My company's supplier gives us an Access
This issue has me baffled, it's affecting a single user (to my knowledge) and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
My issue is simple. I have already implemented a tab system, and I'd probably
My issue is as follows : I have stored a few pictures into the
This issue occurs in our beloved Internet Explorer 7: I have a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.