0

I am getting the cakephp notice 8 on my view.ctp page for Category, Product and Size.

Here is my ProductsController for view:

public function view($id) {
    $result = $this->Product->find('all', array(
        'contain' => array(
            'Category' => array(
                'Size'
            )

        ),
        'conditions' => array(
            'Product.id' => $id
        )

    ));

     $this->set(compact(
        'result'
    ));

Here is the view.ctp:

<?php

$product = $result['Product'];
$category = $result['Category'];
$sizes = $category['Size'];

pr($result);

echo "<h2>" . $product['name'] . "</h2>";
echo "<div>". $product['description'] . "</div>";

echo $this->Form->create();
echo $this->Form->input('sizes');


echo "<h3>" . $size['name'] . "</h3>";

//echo $this->Html->link('Add to Paypal cart', $paypalUrl);

echo '<br />';
echo '<br />';

echo '<h3>Add to cart</h3>';

echo $this->Form->create(false); //  FALSE FOR NO MODEL
echo $this->Form->input('quantity');
echo $this->Form->submit('Add to cart');
echo $this->Form->end();


?>

I did a pr($result); and the Array showed all the information that I need:

Array
(
    [0] => Array
        (
            [Product] => Array
                (
                    [id] => 115
                    [name] => Curly Indian Fusions Extensions
                    [description] => Small groups of luxurious 100% virgin human hair strands are matched to coloured high-quality keratin tips
                    [image] => ../webroot/img/hciImages/curlyVirginUtipSMA.jpg
                    [category_id] => 10
                    [created] => 0000-00-00
                    [modified] => 0000-00-00
                )

            [Category] => Array
                (
                    [id] => 10
                    [name] => Indian Fusion Extensions
                    [desc] => Small groups of luxurious 100% virgin human hair strands are attached to matched colour high quality keratin tips.
                    [Size] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 225
                                    [name] => 12 inches
                                    [category_id] => 10
                                    [price] => 2.50
                                )

                            [1] => Array
                                (
                                    [id] => 226
                                    [name] => 14 inches
                                    [category_id] => 10
                                    [price] => 2.50
                                )

                            [2] => Array
                                (
                                    [id] => 227
                                    [name] => 16 inches
                                    [category_id] => 10
                                    [price] => 2.50
                                )

                            [3] => Array
                                (
                                    [id] => 228
                                    [name] => 18 inches
                                    [category_id] => 10
                                    [price] => 3.00
                                )

                            [4] => Array
                                (
                                    [id] => 229
                                    [name] => 20 inches
                                    [category_id] => 10
                                    [price] => 3.50
                                )

                            [5] => Array
                                (
                                    [id] => 230
                                    [name] => 22 inches
                                    [category_id] => 10
                                    [price] => 3.50
                                )

                            [6] => Array
                                (
                                    [id] => 231
                                    [name] => 24 inches
                                    [category_id] => 10
                                    [price] => 4.50
                                )

                            [7] => Array
                                (
                                    [id] => 232
                                    [name] => 26 inches
                                    [category_id] => 10
                                    [price] => 4.60
                                )

                        )

                )

        )

)

So all the information is there, but not displaying. I have a feeling I've not called the information properly but can't figure why the information is not defined if it is there. Any guidance is appreciated, I'm a noob.

Thank you

3
  • Maybe this typo: echo "<h3>" . $size['name'] . "</h3>"; because you created a $sizes array
    – AgRizzo
    Apr 24, 2015 at 19:23
  • You didnt specify version of Cake you are using. But, if 2.x, you could use first instead of all. Like $result = $this->Product->find('first', array(. Your view will then work... as is
    – AKKAweb
    Apr 24, 2015 at 20:18
  • Thank you! Using 'first' helped! Now the sizes aren't displaying but as AgRizzo pointed out I'll need to make a select dropdown, which I read about in the formHelper section of the documentation. I'm going to go and play with that. Thank you again for all of your help friends!
    – CHAR A. B.
    Apr 24, 2015 at 22:08

1 Answer 1

0

You should use loop for represent data of $result. in this case just replace

$product = $result[0]['Product'];
$category = $result[0]['Category'];
$sizes = $category['Size'];

instead

$product = $result['Product'];
$category = $result['Category'];
$sizes = $category['Size']

Update :

foreach($sizes as $size)  {
   echo "<h3>" . $size['name'] . "</h3>";
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.