我有一个我在cgridview中创建的注册按钮我需要知道我们是否可以在控制器buuton中执行操作,并且在yii中没有针对该按钮的特定操作的视图
查看用户
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(
'name',
'email',
array(
'class'=>'CButtonColumn',
'template'=>'{Register}{update}{view}',
'buttons'=>array(
'Register'=>array(
'label'=>'Register',
.'url'=>Yii::app()->createUrl('register/create',array( 'email'=>$data->email) )
)
),
),
),
)); ?>
控制器用户
public function actionCreate($email)
{
$model=$this->loadModel($email);
if($_SESSION['userid'])
{
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
));
}
//$this->redirect(array('display','id'=>$model->productid));
$this->redirect(array('user/login'));
}
我没有得到错误,但接下来的行不是我看的网址 /localhost/test/index.php/register/create/product/create
它应该是 /localhost/test/index.php/product/create/id/1我认为第1行出了点问题
请让我知道如何解决此问题
答案 0 :(得分:1)
更改此
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
到
$this->redirect(Yii::app()->createUrl('product/create',array( //line 1
'id'=>$model->productid))
答案 1 :(得分:0)
您可以参数化各个CButtonColumn实例:
array(
'class' => 'CButtonColumn',
'template' => '{Register}{view}{update}',
'buttons' => array(
'Register' => array(
'label' => 'Register',
'url'=>Yii::app()->createUrl('register/create', array('email' => $data->email)),
'visible'=>'$data->entries == 0',
),
'view' => array(
'visible'=>'$data->entries > 0',
)
)
),
但是在你更新你的回复之后回答你的问题(我已经输入了)
您可以使用原始类型:
'type'=>'raw',
并且网址变为:
'url'=>'Yii::app()->createUrl("register/create",array( "email"=>$data->email) )'
thx to @ let-me-see
来源:http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/#hh2
答案 2 :(得分:0)
这是有效的
$this->redirect(array('product/create','id'=>$model->productid));