Note that there are some explanatory texts on larger screens.

plurals
  1. PONotice (8): Undefined index: id
    primarykey
    data
    text
    <p>I'm trying to get the view to work. My model is:</p> <pre><code>class LocalClock extends AppModel { public $useDbConfig = 'default'; public $useTable = 'local_clocks'; //public $useTable = false; public function setStatType( $type ) { //$this-&gt;table = 'local_clocks'; $this-&gt;_schema = array( 'col1' =&gt; array('type' =&gt; 'int') ,'col2' =&gt; array('type' =&gt; 'string') ,'col3' =&gt; array('type' =&gt; 'string') ,'col4' =&gt; array('type' =&gt; 'string') ,'col5' =&gt; array('type' =&gt; 'string') ,'col6' =&gt; array('type' =&gt; 'string') ,'col7' =&gt; array('type' =&gt; 'string') ,'col8' =&gt; array('type' =&gt; 'string') ,'col9' =&gt; array('type' =&gt; 'string') ,'col10' =&gt; array('type' =&gt; 'string') ,'col11' =&gt; array('type' =&gt; 'string') ,'col12' =&gt; array('type' =&gt; 'string') ,'col13' =&gt; array('type' =&gt; 'string') ,'col14' =&gt; array('type' =&gt; 'string') ); } </code></pre> <p>}</p> <p>The controller is this:</p> <pre><code>class LocalClocksController extends AppController { public $scaffold = 'admin'; // allow basic view/edit for administrators public $components = array('RequestHandler'); // enable checking for incoming request attributes public $helpers = array('Html', 'Form'); public function index() { if ($this-&gt;RequestHandler-&gt;accepts('xml')) { $this-&gt;LocalClock-&gt;table = 'local_clocks'; $this-&gt;LocalClock-&gt;getDataSource()-&gt;tableFields['local_clocks'] = array( "id", "name", "auto_offset", "utc_offset_sec", "in_month", "in_week", "in_day", "in_hour", "out_month", "out_week", "out_day", "out_hour", "offset_sec"); // xml handler $this-&gt;set('localClocks', $this-&gt;LocalClock-&gt;find('all')); $this-&gt;set('_serialize', array('local_clocks')); } elseif ($this-&gt;RequestHandler-&gt;accepts('json')) { $this-&gt;LocalClock-&gt;getDataSource()-&gt;tableFields['local_clocks'] = array( "id", "name", "auto_offset", "utc_offset_sec", "in_month", "in_week", "in_day", "in_hour", "out_month", "out_week", "out_day", "out_hour", "offset_sec"); $this-&gt;set('localClocks', $this-&gt;LocalClock-&gt;find('all')); $this-&gt;set('_serialize', array('local_clocks')); } elseif( $this-&gt;RequestHandler-&gt;accepts('html')) { $this-&gt;LocalClock-&gt;table = 'local_clocks'; $this-&gt;LocalClock-&gt;getDataSource()-&gt;tableFields['local_clocks'] = array( "id", "name", "auto_offset", "utc_offset_sec", "in_month", "in_week", "in_day", "in_hour", "out_month", "out_week", "out_day", "out_hour", "offset_sec"); $this-&gt;set('localClocks', $this-&gt;LocalClock-&gt;find('all')); } } </code></pre> <p>}</p> <p>And this is the view:</p> <pre><code>&lt;p&gt;&lt;marquee&gt;&lt;u&gt;Local Clocks&lt;/u&gt;&lt;/marquee&gt;&lt;/p&gt; &lt;table&gt; &lt;thead&gt;&lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Auto Offset&lt;/th&gt; &lt;th&gt;UTC Offset Sec&lt;/th&gt; &lt;th&gt;In Month&lt;/th&gt; &lt;th&gt;In Week&lt;/th&gt; &lt;th&gt;In Day&lt;/th&gt; &lt;th&gt;In Hour&lt;/th&gt; &lt;th&gt;Out Month&lt;/th&gt; &lt;th&gt;Out Week&lt;/th&gt; &lt;th&gt;Out Day&lt;/th&gt; &lt;th&gt;Out Hour&lt;/th&gt; &lt;th&gt;Offset Sec&lt;/th&gt; &lt;th&gt;Actions&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach($localClocks as $LocalClock) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $LocalClock['id']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="button" value="View"/&gt;&lt;input type="button" value="Edit"/&gt;&lt;input type="button" value="Delete"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php debug($LocalClock); ?&gt; </code></pre> <p>I am getting the "Notice (8): Undefined index: id [APP/View/LocalClocks/index.ctp, line 37]" error</p> <p>This is the output of debug($LocalClock) (the LocalClock from the foreach loop in the view file</p> <pre><code>array( 'LocalClock' =&gt; array( 'id' =&gt; '4', 'name' =&gt; 'New Test Clock', 'auto_offset' =&gt; false, 'utc_offset_sec' =&gt; '9', 'in_month' =&gt; '8', 'in_week' =&gt; '7', 'in_day' =&gt; '6', 'in_hour' =&gt; '5', 'out_month' =&gt; '4', 'out_week' =&gt; '3', 'out_day' =&gt; '2', 'out_hour' =&gt; '1', 'offset_sec' =&gt; '0' ) ) </code></pre> <p>Any help with how to correctly display the id would be great. I am also trying to display the other properties like the auto-offset, utc_offset_sec, in_month etc but i left those out of the view file for simplicity.</p> <p>Also, in the model file at the top, do I really need the function setStateType($type) ? And if i do need the function, what about the $this->_schema = array() code, do I need that as well.</p> <p>I am using cakephp, and I am new to this. ALso, the code I have is from a different section of the same big project I am working on.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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