Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp Unidentified Index problem
    text
    copied!<p>Hi been trying to get this to work for ages,</p> <p>i have a deals controller </p> <pre><code>&lt;?php class DealsController extends AppController { var $name = 'Deals'; var $helpers = array('HTML', 'Javascript', 'Form', 'Time', 'Ajax'); var $components = array('RequestHandler', 'Session', 'Cookie'); var $uses = array('Deal', 'City', 'Partner'); function beforeFilter(){ parent::beforeFilter(); if(strpos($this-&gt;here, 'admin')){ $this-&gt;layout = 'admin'; } } function view($id = null) { if (!$id) { $this-&gt;Session-&gt;setFlash(__('Invalid deal', true)); $this-&gt;redirect(array('action' =&gt; 'index')); } $this-&gt;set('deal', $this-&gt;Deal-&gt;read(null, $id)); } function by_city($CityID = null) { $city = $this-&gt;paginate = array( 'conditions' =&gt; array('City.id' =&gt; $CityID), 'limit' =&gt; 1 ); $this-&gt;set('city',$city); $this-&gt;Retailer-&gt;recursive = -1; $this-&gt;paginate = array( 'conditions' =&gt; array('Deal.city_id' =&gt; $CityID), 'order' =&gt; array('Deal.start'=&gt;'desc'), 'limit' =&gt; 3 ); $this-&gt;set('deals',$this-&gt;paginate()); } </code></pre> <p>and the by_city view is :</p> <pre><code>&lt;h3&gt;More Deals from &lt;?php echo $city['City']['city'];?&gt;&lt;/h3&gt; </code></pre> <p>Now when i run this i am getting a "unidentified index City" notice</p> <p>when i run var_dump it says that theres an array City and 'city' has a value aswell which sounds to me like the controller has passed this </p> <p>i'm lost now lol</p> <p>All help appreciated, if you need more info just ask :)</p> <p>Edit: Changed code - its still not identifying the variable City </p> <p>here is the var_dump to show that the controller is passing it:</p> <pre><code>array(1) { [0]=&gt; array(3) { ["Deal"]=&gt; array(15) { ["id"]=&gt; string(1) "2" ["... this part of is fine so ill hide this part of the var_dump } ["City"]=&gt; array(2) { ["id"]=&gt; string(1) "1" ["city"]=&gt; string(7) "Glasgow" } } } </code></pre> <p>as you can see $city['City']['city'] is being passed. PS i will change the name of this field ;)</p> <p>Thanks Dave</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload