Sry for being so straight but i've search some of the topic but i just don't understand..
Let's say i have 2 tables..
First is Brand with brand_id and brand_name as variable
table brand
brand_id (int)
brand_name (varchar)
the next table is product
table product
product_id (int)
product_brand (id), references to table brand (brand_id)
product_name (varchar)
but in the view.php when showing the product.. instead of showing the product_brand (id), i want to show the product name
example
product_id: 114326
product_brand: Samsung (instead of the id, show the name)
product_name: Galaxy Note 10.1
how to do that?
Page 1 of 1
Display Relational Data...
#2
Posted 21 November 2012 - 11:36 PM
karasawaz, on 21 November 2012 - 11:16 PM, said:
Sry for being so straight but i've search some of the topic but i just don't understand..
Let's say i have 2 tables..
First is Brand with brand_id and brand_name as variable
table brand
brand_id (int)
brand_name (varchar)
the next table is product
table product
product_id (int)
product_brand (id), references to table brand (brand_id)
product_name (varchar)
but in the view.php when showing the product.. instead of showing the product_brand (id), i want to show the product name
example
product_id: 114326
product_brand: Samsung (instead of the id, show the name)
product_name: Galaxy Note 10.1
how to do that?
Let's say i have 2 tables..
First is Brand with brand_id and brand_name as variable
table brand
brand_id (int)
brand_name (varchar)
the next table is product
table product
product_id (int)
product_brand (id), references to table brand (brand_id)
product_name (varchar)
but in the view.php when showing the product.. instead of showing the product_brand (id), i want to show the product name
example
product_id: 114326
product_brand: Samsung (instead of the id, show the name)
product_name: Galaxy Note 10.1
how to do that?
In the 'attributes' array of your CDetailView, try this:
array( 'name'=>'prod_brand', 'value'=>$model->brand->brand_name),
in place of the 'product_brand' entry you must be having in your code....dont forget to define $prod_brand in your model else it throws undefined errors...
for it to work you must have your relations specified in your model...generate your model using gii and it would create the relations for you....
#3
Posted 20 January 2013 - 10:15 PM
Quote
//This is the CDetailView code from view.php
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'code',
'name',
'brand_id', //i want to show the name instead of id
'category_id',
'description',
'image_path',
'price',
'active',
),
)); ?>
//And this is the code from _view.php
<b><?php echo CHtml::encode($data->getAttributeLabel('brand_id')); ?>:</b>
<?php echo CHtml::encode($data->brand_id); ?>
<br />
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'code',
'name',
'brand_id', //i want to show the name instead of id
'category_id',
'description',
'image_path',
'price',
'active',
),
)); ?>
//And this is the code from _view.php
<b><?php echo CHtml::encode($data->getAttributeLabel('brand_id')); ?>:</b>
<?php echo CHtml::encode($data->brand_id); ?>
<br />
That's the CDetailView in my view.php, could u specify the modified part of the view?
#4
Posted 21 January 2013 - 03:51 AM
You can try:
And brand should be specified as a relations in your model.
//This is the CDetailView code from view.php
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'code',
'name',
array( 'name'=>'prod_brand', 'value'=>$data->brand->product_name),
'category_id',
'description',
'image_path',
'price',
'active',
),
)); ?>
//And this is the code from _view.php
<b><?php echo CHtml::encode($data->getAttributeLabel('brand_id')); ?>:</b>
<?php echo CHtml::encode($data->brand_id); ?>
<br />
And brand should be specified as a relations in your model.
Share this topic:
Page 1 of 1

Help













