and i have product default view which created by gii and it display some result that doesn’t match my functionality
View :: product
product_id :: 1 (CHtml::link)
product_name :: Silver Ring
product_price :: 4000 $
productcategory_id :: 1 (in this case i assumed product category 1 equal to accessories) and link to Productcategory model to show productcategory description when click on the link
the problem is how can i show productcategory_id to productcategory_name
sorry for my noob question , i actually wanna know about the correctly way to solved this problem by MVC solution
this is my code that i 've ever try out
In my Product :: Model
public function getProductCategoryName($_productcategoryid)
{
$productcategoryname=Productcategoryname::model()->findByPk($_productcategoryid);
echo $temp=$productcategoryname->productcategoryname;
return $temp;
}
I dont really understand what you mean, but if you wish to get the products under a category you should:
set a relationship on your productcategory model:
public function relations(){
return array('products'=>array(self::MAS_MANY, 'Product','product_category'));
}
Then on the categories product, for view, you do get the id passed by the parameter and load a model productcategory: $model = $this->loadModel($_REQUEST[‘id’]); and pass the resulting model to the view:
$this->render('view', array('model'=>$model));
On the view you can loop through the products if any to display the products under that category