cakephp notice 8: undefined index: -
i getting cakephp notice 8 on view.ctp page category, product , size.
here productscontroller 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 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 paypal cart', $paypalurl); echo '<br />'; echo '<br />'; echo '<h3>add cart</h3>'; echo $this->form->create(false); // false no model echo $this->form->input('quantity'); echo $this->form->submit('add cart'); echo $this->form->end(); ?> i did pr($result); , array showed information need:
array ( [0] => array ( [product] => array ( [id] => 115 [name] => curly indian fusions extensions [description] => small groups of luxurious 100% virgin human hair strands matched 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 attached 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 information there, not displaying. have feeling i've not called information can't figure why information not defined if there. guidance appreciated, i'm noob.
thank you
you should use loop represent data of $result. in case 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 $size) { echo "<h3>" . $size['name'] . "</h3>"; }
Comments
Post a Comment