php - Notice (8): Undefined index: id -
i'm trying view work. model is:
class localclock extends appmodel { public $usedbconfig = 'default'; public $usetable = 'local_clocks'; //public $usetable = false; public function setstattype( $type ) { //$this->table = 'local_clocks'; $this->_schema = array( 'col1' => array('type' => 'int') ,'col2' => array('type' => 'string') ,'col3' => array('type' => 'string') ,'col4' => array('type' => 'string') ,'col5' => array('type' => 'string') ,'col6' => array('type' => 'string') ,'col7' => array('type' => 'string') ,'col8' => array('type' => 'string') ,'col9' => array('type' => 'string') ,'col10' => array('type' => 'string') ,'col11' => array('type' => 'string') ,'col12' => array('type' => 'string') ,'col13' => array('type' => 'string') ,'col14' => array('type' => 'string') ); } }
the controller this:
class localclockscontroller extends appcontroller { public $scaffold = 'admin'; // allow basic view/edit administrators public $components = array('requesthandler'); // enable checking incoming request attributes public $helpers = array('html', 'form'); public function index() { if ($this->requesthandler->accepts('xml')) { $this->localclock->table = 'local_clocks'; $this->localclock->getdatasource()->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->set('localclocks', $this->localclock->find('all')); $this->set('_serialize', array('local_clocks')); } elseif ($this->requesthandler->accepts('json')) { $this->localclock->getdatasource()->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->set('localclocks', $this->localclock->find('all')); $this->set('_serialize', array('local_clocks')); } elseif( $this->requesthandler->accepts('html')) { $this->localclock->table = 'local_clocks'; $this->localclock->getdatasource()->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->set('localclocks', $this->localclock->find('all')); } } }
and view:
<p><marquee><u>local clocks</u></marquee></p> <table> <thead><tr> <th>id</th> <th>name</th> <th>auto offset</th> <th>utc offset sec</th> <th>in month</th> <th>in week</th> <th>in day</th> <th>in hour</th> <th>out month</th> <th>out week</th> <th>out day</th> <th>out hour</th> <th>offset sec</th> <th>actions</th> </tr></thead> <tbody> <?php foreach($localclocks $localclock) { ?> <tr> <td><?php echo $localclock['id']; ?></td> <td><input type="button" value="view"/><input type="button" value="edit"/><input type="button" value="delete"/></td> </tr> <?php } ?> </tbody> </table> <?php debug($localclock); ?> i getting "notice (8): undefined index: id [app/view/localclocks/index.ctp, line 37]" error
this output of debug($localclock) (the localclock foreach loop in view file
array( 'localclock' => array( 'id' => '4', 'name' => 'new test clock', 'auto_offset' => false, 'utc_offset_sec' => '9', 'in_month' => '8', 'in_week' => '7', 'in_day' => '6', 'in_hour' => '5', 'out_month' => '4', 'out_week' => '3', 'out_day' => '2', 'out_hour' => '1', 'offset_sec' => '0' ) ) any how correctly display id great. trying display other properties auto-offset, utc_offset_sec, in_month etc left out of view file simplicity.
also, in model file @ top, need function setstatetype($type) ? , if need function, $this->_schema = array() code, need well.
i using cakephp, , new this. also, code have different section of same big project working on.
thanks
like this:
$localclock['localclock']['id']; iirc, cakephp puts model name first element in array need access localclock first.
your debug shows this:
array( 'localclock' => array( //this 1 ^ 'id' => '4', 'name' => 'new test clock', 'auto_offset' => false, 'utc_offset_sec' => '9', 'in_month' => '8', 'in_week' => '7', 'in_day' => '6', 'in_hour' => '5', 'out_month' => '4', 'out_week' => '3', 'out_day' => '2', 'out_hour' => '1', 'offset_sec' => '0' ) )
Comments
Post a Comment