Dear all,
i have a problem:
- when i click menu root, it will display root item & with link /gg/index.php/root/1 for each item (1 is id)
-after click item in root page, i click on the category item but
they are with link /gg/index.php/root/1.
this is the problem, it should display link /gg/index.php/category/1
So , i can not view the the products page by there.
can you help me fix the problem? any help will be appreciated, thanks…
below is my description about my file & table.
I have 3 table,
root ==> id, title
category ==> id, title, root_id
products ==> id, title, description, category_id
ar in Model:
root :
'category'=>array(self::HAS_MANY,'Category','root_id'),
category :
'products'=>array(self::HAS_MANY,'Products','category_id'),
'root'=>array(self::BELONGS_TO,'Root','root_id'),
products :
'category'=>array(self::BELONGS_TO,'Category','category_id'),
Controller:
*root:
public function actionView($id)
{
$categoriesDataProvider = new CActiveDataProvider('Category', array(
'criteria'=>array(
'condition'=>'root_id=:rootId',
'params'=>array(':rootId'=>$id),
),
'pagination'=>array('pageSize'=>6,
),
));
$this->render('view',array(
'model'=>$this->loadModel($id),'categoryDataProvider'=>$categoriesDataProvider,
));
}
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Root');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
*category :
public function actionView($id)
{
$productsDataProvider = new CActiveDataProvider('Products', array(
'criteria'=>array(
'condition'=>'category_id=:categoryId',
'params'=>array(':categoryId'=>$id),
),
'pagination'=>array('pageSize'=>6,
),
));
$this->render('view',array(
'model'=>$this->loadModel($id),'productDataProvider'=>$productsDataProvider,
));
}
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Category');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
*products:
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Products',array(
'pagination'=>array(
'pageSize'=>6,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
in the view.php:
*root:
$this->widget('zii.widgets.CListView',array(
'dataProvider'=>$categoryDataProvider,
'itemView'=>'/category/_view',
));
*category:
$this->widget('zii.widgets.CListView',array(
'dataProvider'=>$productDataProvider,
'itemView'=>'/products/_view',
));
*products:
$this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
array('name'=>'image',
'htmlOptions'=>array('width'=>200),
'value'=>CHtml::image('../../images/'.$model->image,$model->id,array('width'=>200,'height'=>200)),
'type'=>'raw',
),
'title',
'description',
'price',
array('name'=>'category_id',
'value'=> CHtml::encode($model->category->title),
),
),
));
Thanks guys
Best Regard,
Ichigo