1

模型 -

enter code here
 public function searchShop()
{
        $criteria = new CDbCriteria();
            $criteria->compare("name", $this->category, TRUE, "OR");
                $criteria->compare("shopname", $this->category, TRUE, "OR");
                    $criteria->compare("category", $this->category, TRUE, "OR");

            return Shops::model()->findAll($criteria);  
}

代码 - -

enter code here
<?php 
foreach($models as $model):
    $this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
'ID' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('name' => 'ID', 'label' => 'ID'),
),
)
);

echo "<br><hr><br>";
 endforeach;
 ?>

我想要一个关于 ID 的链接,点击它会呈现视图文件,即商店模型的 view.php

我使用 CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID)) 但它显示该视图的路径为1

帮助我...提前谢谢

4

1 回答 1

1

尝试

 CHtml::link(CHtml::encode($model->ID),
CController::createUrl('site/view',array('id'=>$model->ID)))

在这里,我假设动作视图位于站点控制器中。如果它位于其他模块名称下,那么您可以这样写"moduleName/controllerName/actionName"

编辑: 好的,你必须尝试一些事情。TbDetailView 扩展了 CetatilView。现在您可以使用 TbDetailView 作为

$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('label' => 'ID', 'value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))),
),
)
);

你也可以这样做

 $this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' =>$model,
'attributes' => array(
array('name' => 'shopname', 'label' => 'Shop name'),
array('name' => 'category', 'label' => 'Category'),
array('value' =>  CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),, 'label' => 'ID'),
),
)
)

;

于 2014-03-05T11:27:14.000 回答