Issue
When I am try pick a manufacturer name and upload the manufacturer logo image I want the image name to the manufacturer name. But the file name is always Array.
Can someone check the below code and tell me what is wrong?
View.ctp
<fieldset>
<label>Manufacturer</label>
<?php
echo $this->Form->input('manufacturer_id', array('options' => $manufacturers));
?>
</fieldset>
controller.ctp
$manufacturer_name=$this->Manufacturer->findById($product_data['Product']['manufacturer_id']);
$new_image_name = $manufacturer_name;
Solution
Cakephp 2 returns query result in the form of [ModelName] array.
You can access any field by using [ModelName][fieldName]
Array
(
[ModelName] => Array
(
[id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
You can access Manufacturer name as (assuming manufacturer name is stored in name column)
$new_image_name = $manufacturer_name['Manufacturer']['name'];
For further reading: https://book.cakephp.org/2.0/en/models/retrieving-your-data.html
Answered By - Sehdev
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.