Im pulling the data successfully but Im trying to get the "name" value
as opposed to the "id" value in a separate table.
When I do debug I get this:
(
[Product] => Array
(
[id] => 21
[color_id] => 3
[image_thumb] => aw_ls_black.png
[price] => 27.95
[shipping_price] => 5.00
[style_id] => 1
)
[Style] => Array
(
[id] => 1
[name] => All Weather Longsleeve Compression Shirt
[gender_id] => 2
[category_id] => 2
[material_id] => 2
[application_id] => 2
For sake of example I will just reference the gender_id. I need it to
show the name not the id.
I have the following tables/models.
Products
Styles
Genders
Product Model:
class Product extends AppModel {
var $name = 'Product';
var $belongsTo = array(
'Style' => array(
'className' => 'Style',
'foreignKey' => 'style_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
}
Styles Model:
class Style extends AppModel {
var $name = 'Style';
var $belongsTo = array(
'Gender' => array(
'className' => 'Gender',
'foreignKey' => 'gender_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Category' => array(
'className' => 'Category',
'foreignKey' => 'category_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Material' => array(
'className' => 'Material',
'foreignKey' => 'material_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Application' => array(
'className' => 'Application',
'foreignKey' => 'application_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
Gender Model:
var $name = 'Gender';
var $hasMany = array(
'Style' => array(
'className' => 'Style',
'foreignKey' => 'gender_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>
The page im trying to get this on is my product view page. Action
looks like this:
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('product', $this->Product->read(null, $id));
}
Ive been playing with this for hours and I just cant seem to get it.
If you need more info, please dont hesitate to ask.
Your help is greatly appreciated.
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---