FSShaikh
FSShaikh

Reputation: 125

bootstrap.widgets.TbDetailView, Yii app

Model--

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);  
}

code----

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;
 ?>

I want a link on ID by clicking on it it will render view file i.e view.php of shops model

I used CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID)) but it is showing path of that view as 1

help me... thanks in advance

Upvotes: 1

Views: 2860

Answers (1)

Rafay Zia Mir
Rafay Zia Mir

Reputation: 2116

try

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

here i have assumed that action view lies in site controller. If it lies under some other module name then you can write like this "moduleName/controllerName/actionName"

Edit: Ok you have to try a few things. TbDetailView extends CDetatilView. Now you can use TbDetailView as

$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))),
),
)
);

You can also do like

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

;

Upvotes: 1

Related Questions