Get latest SQL query
When debugging CakePHP code, it’s very useful to know which SQL query is executed latest. Use next few lines to get this information $log = $this->Model->getDataSource()->getLog(false, false); debug($log);
When debugging CakePHP code, it’s very useful to know which SQL query is executed latest. Use next few lines to get this information $log = $this->Model->getDataSource()->getLog(false, false); debug($log);
How to return primary key of last inserted record (ID) generated in the last query, like LAST_INSERT_ID() in MySQL or mysql_insert_id() in PHP echo (int)$this->ModelName->getLastInsertID(); No need to explain more, right? 😉
Here is example how to add onChange event in option-select (combo) form element. $packages = array(‘1’=>’First’, ‘2’=>’Second’, ‘3’=>’Third’); // define some select-option element // next will integrate onChange event into it echo $form->input(‘package_id’, array(‘options’ => $packages, ‘label’=>array(‘Package’), ‘onchange’ => “alert(‘Message!’)” )); Of course, $packages array can be defined in controller also (it’s even better to…