且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在yii中调用cgiGrid视图中的小部件

更新时间:2022-11-04 21:11:51

CGridView需要一个php表达式作为 value ,一旦它被评估,就会产生一个字符串


  1. php表达式需要作为字符串传递
  2. $ captureOutput (最后一个参数) CController :: widget() 需要设置为true才能捕获小部件,而不是直接将其发送到显示器。
  3. 在PHP表达式中,
  4. $ this 引用列对象,所以应该使用 $ this-> grid->控制器


$来引用控制器b $ b

因此:

 'value'=> 'DropDownRedirect',
array(data=> array(1=>1,2=> 2,3=>3)),
true)'


I have custom widget... I just want to call the widget in Tbgridview...

Here is code..

$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'test1',
'type' => 'striped bordered condensed',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'name',
    'addr',
    'email',

     array(

                   'type'  => 'raw',
                    'value' => $this->widget('DropDownRedirect', array(
                                 'data' => array('1'=>'1','2'=>'2','3'=>'3'))),
                 ),
           )
     ));

its not working.. can anybody help me?...

please refer the class DropdownRedirect given below.

class DropDownRedirect extends CWidget {
public $name; 

public $select; 

public $data; 

public $htmlOptions = array(); 

public $url;

public $replacement = '__value__';

protected function registerScript() {
    $script = '$("#'.$this->id.'").change(function(){'
    .'$(location).attr("href", "'.$this->url.'".replace("'.$this->replacement.'", $(this).val()));'
    .'});';
    Yii::app()->clientScript->registerScript(__CLASS__.$this->id, $script);
}

public function init() {
    if (! isset($this->name))
        $this->name= $this->id;
    $this->registerScript();
}

public function run() {
    if (!isset($this->htmlOptions['id'])) $this->htmlOptions['id'] = $this->id;
    echo CHtml::dropDownList($this->name, $this->select, $this->data, $this->htmlOptions);
}}

Thanks in advance

CGridView expects a php expression as value that results in a string once it is evaluated so

  1. the php expression needs to be passed as a string
  2. $captureOutput (last parameter) of CController::widget() needs to be set to true in order to capture the widget instead of sending it directly to the display.
  3. in the php expression $this refers to the column object so the controller should be referenced using $this->grid->controller

Thus:

'value' => '$this->grid->controller->widget("DropDownRedirect",
            array("data" => array("1"=>"1","2"=>"2","3"=>"3")),
            true)'