root, category, product not working well

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

hello, any body help?

thanks

Pls, publish code of views contained wrong links generation first…

hi, you mean view.php?

For root




<?php

$this->breadcrumbs=array(

	'Roots'=>array('index'),

	$model->name,

);


$this->menu=array(

	array('label'=>'List Root', 'url'=>array('index')),

	array('label'=>'Create Root', 'url'=>array('create')),

	array('label'=>'Update Root', 'url'=>array('update', 'id'=>$model->id)),

	array('label'=>'Delete Root', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),

	array('label'=>'Manage Root', 'url'=>array('admin')),

);

?>


<h1>View Root #<?php echo $model->id; ?></h1>


<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'id',

		'name',

		'image',

	),

)); ?>

<h2>Category</h2>

<?php

$this->widget('zii.widgets.CListView',array(

    'dataProvider'=>$categoryDataProvider,

    'itemView'=>'/category/_view',


));

?>



for category




<?php

$this->breadcrumbs=array(

	'Categories'=>array('index'),

	$model->title,

);


$this->menu=array(

	array('label'=>'List Category', 'url'=>array('index')),

	array('label'=>'Create Category', 'url'=>array('create'),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Update Category', 'url'=>array('update', 'id'=>$model->id),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Delete Category', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?'),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Manage Category', 'url'=>array('admin'),'visible'=>!Yii::app()->user->isGuest),

);

?>


<h1>View Category <?php echo $model->title; ?></h1>


<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'title',

	),

)); ?>


<h2>Products</h2>

<?php

$this->widget('zii.widgets.CListView',array(

    'dataProvider'=>$productDataProvider,

    'itemView'=>'/products/_view',


));


?>



for Products




<?php

$this->breadcrumbs=array(

	'Products'=>array('index'),

	$model->title,

);




$this->menu=array(

	array('label'=>'List Products', 'url'=>array('index'),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Create Products', 'url'=>array('create'),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Update Products', 'url'=>array('update', 'id'=>$model->id),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Delete Products', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?'),'visible'=>!Yii::app()->user->isGuest),

	array('label'=>'Manage Products', 'url'=>array('admin'),'visible'=>!Yii::app()->user->isGuest),

        array('label'=>'Add Category','url'=>array('/category/create'),'visible'=>!Yii::app()->user->isGuest),

);




?>


<h1>Product <?php echo $model->title; ?></h1>


<?php $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 for your reply