1

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

FSShaikh
  • 125
  • 3
  • 18

1 Answers1

1

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

;

Rafay Zia Mir
  • 2,116
  • 6
  • 23
  • 49
  • I did the same.. 'ID' => CHtml::link(CHtml::encode($model->ID), CController::createUrl('shops/view',array('id'=>$model->ID))) Its not working – FSShaikh Mar 07 '14 at 05:35
  • not working? is the link being showing correctly? is it clickable? what is it showing? – Rafay Zia Mir Mar 07 '14 at 10:38
  • Link is correct but not clickable... showing link for that ID.. i am using URL manager... is it wrong to use URL manager??? – FSShaikh Mar 08 '14 at 10:01
  • No if it is not clickable then it is not an issue of URL manager. Please correct me if i am wrong. It only shows you 1? Means $model->id is so it only shows you 1 but not clickable? – Rafay Zia Mir Mar 08 '14 at 10:39
  • CHtml::link(CHtml::encode($model->ID), CController::createUrl('site/view',array('id'=>$model->ID))) shows url string instead of showing ID having link to view.php page... it shows url address as 1 – FSShaikh Mar 08 '14 at 10:41
  • please see edits if it helps. If one solution does not work then try the other one also – Rafay Zia Mir Mar 08 '14 at 10:56
  • thanks for the help... i did it.. only change is.. 'ID' => CHtml::link(CHtml::encode($model->ID), array('shops/view', 'id'=>$model->ID)), CHtml::link(CHtml::encode($model->city->name),array('city/view','id'=>$model->city->id)), 'Shop Name' =>CHtml::link(CHtml::encode($model->shopname),array('shops/view','id'=> $model->ID)), 'Category' => $model->category ), 'attributes' => array( array('name' => 'ID','label' => 'ID','value'=>CHtml::link(CHtml::encode($model->ID), array('shops/view', 'id'=>$model->ID)),'type'=>'raw'), – FSShaikh Mar 15 '14 at 08:43