当我从其他模型调用数据时,为什么我在yii管理用户时缺少搜索框?

Why does the text box disappear below Created By when I call the value from an other model(admin) relation. How can I get the textbox to display no matter what model relation?

Refer to the screenshot for more information about the problem:

screenshot

Yii CGridView doesn't create inputFiled for those columns that aren't part of the tables shown (as occurs with relations). If you want to show a filter box (dropdown, or whatever you want, an easy way is to create a custom CDataColumn an use it in your grid:

array(
    'name'=>'customer.createdBy.name',
    'header' => 'Created by',
    'class' => 'application.modules.mine.components.DataColumnCreatedBy',
),

Now define your extended column to render a filter:

class DataColumnCreatedBy extends CDataColumn
{
    public function renderFilterCell()
    {
        echo "<td>";
        echo CHtml::inputField('createdBy');
        echo "</td>";
    }
}

Best solution is to add drop down list as you must have ids in createdBy field and dont want users to search using numerical ids. The following article can help you in that

http://help.discretelogix.com/php/yii/replace-text-box-with-drop-down-list-in-filter-of-cgridview.htm

if you still want to add textbox then simply assign the textbox html i.e. <input type="text" name="ModelName[createdBy]"> to "filter" property of CDataColumn

'column_id'=> array(
        'name' => 'createdBy',
        'value' => '$data->relatedModel->createdBy',
        'filter'=> '<input type="text" name="ModelName[createdBy]">'

),

Hope this helps