在yii中调用cgiGrid视图中的小部件 [英] call widget inside cgiGrid view in yii

查看:170
本文介绍了在yii中调用cgiGrid视图中的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义小部件...我只想在Tbgridview中调用小部件...



这是代码..

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

数组(

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

));

不工作..任何人都可以帮我吗?...

请参考下面给出的DropdownRedirect类。

  class DropDownRedirect extends CWidget {
public $名称;

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- >编号;
$ 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);
}}

预先致谢

解决方案

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)'

这篇关于在yii中调用cgiGrid视图中的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆