<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1371670590739165117</id><updated>2012-02-07T08:04:04.786+08:00</updated><category term='simplexml_load_string'/><category term='routes'/><category term='PHP'/><category term='xml'/><category term='dropdown tree'/><category term='if else'/><category term='versatile'/><category term='find(&apos;list&apos;)'/><category term='encoding'/><category term='dynamic'/><category term='merge array'/><category term='session'/><category term='layout'/><category term='javascript file'/><category term='empty options'/><category term='SimpleXMLElement'/><category term='headers already sent'/><category term='large array'/><category term='cakePHP 1.2'/><category term='cakePHP'/><category term='error'/><category term='generatetreelist'/><title type='text'>Experiences on PHP Programming</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-5342172756689166185</id><published>2011-02-08T17:48:00.000+08:00</published><updated>2011-02-08T17:48:57.651+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='layout'/><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><title type='text'>How To Customize Main Layout of Error Pages in cakePHP</title><content type='html'>To customize the contents of each cakePHP errors, you need to create the following pages in this folder /app/views/errors/&lt;br /&gt;- error404.ctp&lt;br /&gt;- missing_action.ctp&lt;br /&gt;- missing_component_class.ctp&lt;br /&gt;- missing_component_file.ctp&lt;br /&gt;- missing_connection.ctp&lt;br /&gt;- missing_controller.ctp&lt;br /&gt;- missing_helper_class.ctp&lt;br /&gt;- missing_helper_file.ctp&lt;br /&gt;- missing_layout.ctp&lt;br /&gt;- missing_model.ctp&lt;br /&gt;- missing_scaffolddb.ctp&lt;br /&gt;- missing_table.ctp&lt;br /&gt;- missing_view.ctp&lt;br /&gt;- private_action.ctp&lt;br /&gt;- scaffold_error.ctp&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But cakePHP is using /views/layouts/default.ctp as layout for these error pages like 404, missing controller, etc. To customize it, you need to create a file /app/app_error.php with the following contents:&lt;br /&gt;&lt;pre&gt;class AppError extends ErrorHandler {&lt;br /&gt; &lt;br /&gt; function _outputMessage($template) {&lt;br /&gt;  $this-&gt;controller-&gt;layout = 'error_template'; // /app/views/layouts/error_template.ctp&lt;br /&gt;  parent::_outputMessage($template);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And create a template file "error_template.ctp" in /app/views/layouts.&lt;br /&gt;&lt;br /&gt;Hope this one helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-5342172756689166185?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/5342172756689166185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=5342172756689166185' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5342172756689166185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5342172756689166185'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2011/02/how-to-customize-main-layout-of-error.html' title='How To Customize Main Layout of Error Pages in cakePHP'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-4741079893290905789</id><published>2010-10-04T14:33:00.000+08:00</published><updated>2010-10-04T14:33:49.583+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP'/><title type='text'>Multiple DB in cakePHP</title><content type='html'>In order to dynamically select DB during runtime in cakePHP is try to do it in Controller or in Model.&lt;br /&gt;&lt;br /&gt;To do it in model:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class User extends AppModel {&lt;br /&gt; var $name = 'User';&lt;br /&gt; &lt;b&gt;var $useDbConfig = 'general_syst';&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; function __construct($id = false, $table = null, $ds = null) {&lt;br /&gt;  &lt;b&gt;$this-&gt;useDbConfig = 'db1';&lt;/b&gt;&lt;br /&gt;  &lt;br /&gt;  parent::__construct($id, $table, $ds);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; // your code here&lt;br /&gt; // ....&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When in controller&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Users extends AppController {&lt;br /&gt; &lt;br /&gt; function action1(){&lt;br /&gt;  &lt;b&gt;$this-&gt;User-&gt;useDbConfig = 'db1';&lt;/b&gt;&lt;br /&gt;  &lt;br /&gt;  $users = $this-&gt;User-&gt;find('all');&lt;br /&gt;  &lt;br /&gt;  // your code here&lt;br /&gt;  // ....&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope this one helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-4741079893290905789?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/4741079893290905789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=4741079893290905789' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4741079893290905789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4741079893290905789'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2010/10/multiple-db-in-cakephp.html' title='Multiple DB in cakePHP'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-4031229393772677780</id><published>2009-11-24T11:22:00.003+08:00</published><updated>2009-11-24T11:48:08.771+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='headers already sent'/><category scheme='http://www.blogger.com/atom/ns#' term='encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><title type='text'>Cannot send session cache limiter</title><content type='html'>Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent&lt;br /&gt;&lt;br /&gt;If you encounter the above problem, try to set the encoding from UTF-8.  UTF-8 encoidng add some characters before &amp;lt;?php&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-4031229393772677780?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/4031229393772677780/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=4031229393772677780' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4031229393772677780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4031229393772677780'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/11/cannot-send-session-cache-limiter.html' title='Cannot send session cache limiter'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-4120381530396454434</id><published>2009-06-30T04:45:00.004+08:00</published><updated>2009-06-30T04:51:31.945+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='SimpleXMLElement'/><category scheme='http://www.blogger.com/atom/ns#' term='simplexml_load_string'/><title type='text'>Access SimpleXMLElement Object Attributes</title><content type='html'>PHP simplexml_load_string is a simple way to extract xml data into an object. If you have the following result from calling &lt;br /&gt;&lt;br /&gt;$obj = simplexml_load_string($xml);&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SimpleXMLElement Object&lt;br /&gt;(&lt;br /&gt;    [@attributes] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [status] =&gt; success&lt;br /&gt;        )&lt;br /&gt;&lt;br /&gt;    [auth] =&gt; SimpleXMLElement Object&lt;br /&gt;        (&lt;br /&gt;            [token] =&gt; dxoYGmwncmntH07jJGro5h0rxNfE2Ni6&lt;br /&gt;            [seq] =&gt; 33&lt;br /&gt;        )&lt;br /&gt;&lt;br /&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;you can access status by&lt;br /&gt;&lt;br /&gt;$obj-&gt;attributes()-&gt;status&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-4120381530396454434?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/4120381530396454434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=4120381530396454434' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4120381530396454434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/4120381530396454434'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/06/access-simplexmlelement-object.html' title='Access SimpleXMLElement Object Attributes'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-168775284942597461</id><published>2009-04-18T03:50:00.011+08:00</published><updated>2009-04-23T05:41:20.049+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP 1.2'/><category scheme='http://www.blogger.com/atom/ns#' term='find(&apos;list&apos;)'/><category scheme='http://www.blogger.com/atom/ns#' term='versatile'/><title type='text'>CakePHP 1.2 Versatile Model find('list')</title><content type='html'>Have you wanted to generate a list of options for your select but wanted the display field to be generated dynamically instead of using cakePHP find('list')?&lt;br /&gt;&lt;br /&gt;This is the case.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;MODEL&lt;br /&gt;User hasOne Info&lt;br /&gt;&lt;br /&gt;   User&lt;br /&gt;       id&lt;br /&gt;       username&lt;br /&gt;       password&lt;br /&gt;       manager_id&lt;br /&gt;   Info&lt;br /&gt;       id&lt;br /&gt;       first_name&lt;br /&gt;       last_name&lt;br /&gt;       email&lt;br /&gt;       sex&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I wanted to generate a list of all Users displaying the first_name, last_name and sex. And I wanted the indexes to be generated with User.id and the display field with this format "Info.last_name, Info.first_name (Info.sex)". I have developed a function to override cakePHP $model-&gt;find.&lt;br /&gt;&lt;br /&gt;In your app_model.php, you include this function:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;class AppModel extends Model {&lt;br /&gt; &lt;br /&gt; function find($type, $options = array()) {&lt;br /&gt;  switch ($type) {&lt;br /&gt;            case 'superlist':&lt;br /&gt;                if(!isset($options['format'])) {&lt;br /&gt;                    $options['format'] = '';&lt;br /&gt;                    for ($i=0; $i&lt;count($options['fields'])-1; $i++){&lt;br /&gt;                     $options['format'] .= "%$i ";&lt;br /&gt;                    }&lt;br /&gt;                    $options['format'] = trim($options['format']);&lt;br /&gt;                }&lt;br /&gt;                &lt;br /&gt;                if (isset($options['index'])){&lt;br /&gt;                 preg_match('/(.*?)\.(.*)/', $options['index'], $match);&lt;br /&gt;                 $index_alias = $match[1];&lt;br /&gt;                 $index_field = $match[2];&lt;br /&gt;                }else{&lt;br /&gt;                 $index_alias = $this-&gt;alias;&lt;br /&gt;                 $index_field = 'id';&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                $options['fields'] = array_merge(array("{$index_alias}.{$index_field}"), $options['fields']);&lt;br /&gt;                $list = $this-&gt;find('all', $options);&lt;br /&gt;                &lt;br /&gt;                $result = array();&lt;br /&gt;                foreach ($list as $row){&lt;br /&gt;                 $result[$row[$index_alias][$index_field]] = $options['format'];&lt;br /&gt;                 &lt;br /&gt;                 foreach ($options['fields'] as $index=&gt;$field){&lt;br /&gt;                  preg_match('/(.*?)\.(.*)/', $field, $match);&lt;br /&gt;                  $field_alias = $match[1];&lt;br /&gt;                  $field_field = $match[2];&lt;br /&gt;                  &lt;br /&gt;                  $result[$row[$index_alias][$index_field]] = &lt;br /&gt;                   str_replace('%'.$index, $row[$field_alias][$field_field], &lt;br /&gt;                      $result[$row[$index_alias][$index_field]]);&lt;br /&gt;                 }&lt;br /&gt;                }&lt;br /&gt;                &lt;br /&gt;                return $result;&lt;br /&gt;             break;                       &lt;br /&gt;&lt;br /&gt;            default:              &lt;br /&gt;                return parent::find($type, $options);&lt;br /&gt;             break;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is how you call the generate list function in your controller action.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;// if you have not declared hasOne Info in User model, this is needed in order for User model generate Info model with it and you can pass condition on Info fields&lt;br /&gt;$this-&gt;User-&gt;bindModel(&lt;br /&gt;   array(&lt;br /&gt;       'hasOne' =&gt; array('Info')&lt;br /&gt;   )&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;$users = $this-&gt;User-&gt;find('superlist',&lt;br /&gt;   array(&lt;br /&gt;       'format' =&gt; '%3, %2 (%1)',&lt;br /&gt;       'index' =&gt; 'User.id', // --&gt; this is the default so you may not pass this option&lt;br /&gt;       'fields' =&gt;&lt;br /&gt;           array(&lt;br /&gt;               'Info.sex', // --&gt; %1&lt;br /&gt;               'Info.first_name', // --&gt; %2&lt;br /&gt;               'Info.last_name', // --&gt; %3&lt;br /&gt;           ),&lt;br /&gt;       'order' =&gt; "Info.first_name, Info.last_name", // -- if you want to sort the option&lt;br /&gt;       'condition' =&gt; "User.manager_id=2 AND Info.lastname='Smith'", // --&gt; if you need some filtering&lt;br /&gt;   )&lt;br /&gt;);&lt;br /&gt;$this-&gt;set(compact('users'));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$users array will contain the following structure:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;array(&lt;br /&gt;   'User.id1' =&gt; 'Info.last_name1, Info.first_name1 (Info.sex1)',&lt;br /&gt;   'User.id2' =&gt; 'Info.last_name2, Info.first_name2 (Info.sex2)',&lt;br /&gt;   'User.id3' =&gt; 'Info.last_name3, Info.first_name3 (Info.sex3)',&lt;br /&gt;   .&lt;br /&gt;   .&lt;br /&gt;   .  &lt;br /&gt;   'User.idN' =&gt; 'Info.last_nameN, Info.first_nameN (Info.sexN)',&lt;br /&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope this post can help you in your future cakePHP 1.2 development.&lt;br /&gt;&lt;br /&gt;Thanks to &lt;a href="http://teknoid.wordpress.com/2008/09/04/findlist-with-three-or-combined-fields/"&gt;http://teknoid.wordpress.com/2008/09/04/findlist-with-three-or-combined-fields/&lt;/a&gt; for giving me inspiration to develop this function.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-168775284942597461?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/168775284942597461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=168775284942597461' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/168775284942597461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/168775284942597461'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/04/cakephp-12-versatile-model-findlist.html' title='CakePHP 1.2 Versatile Model find(&apos;list&apos;)'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-3152785486728264810</id><published>2009-02-14T03:51:00.004+08:00</published><updated>2009-02-14T04:14:26.800+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP 1.2'/><category scheme='http://www.blogger.com/atom/ns#' term='routes'/><title type='text'>CakePHP Routing With Parameters</title><content type='html'>Anything you need to know with cakePHP routing can be found &lt;a href="http://book.cakephp.org/view/542/Defining-Routes"&gt;here&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;Here is an example to illustrate routing with parameters.&lt;br /&gt;&lt;br /&gt;/config/routes.php&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Router::connect(&lt;br /&gt;    '/:controller/:year/:month/:day',&lt;br /&gt;    array('action' =&gt; 'index', 'day' =&gt; null),&lt;br /&gt;    array(&lt;br /&gt;        'year' =&gt; '[12][0-9]{3}',&lt;br /&gt;        'month' =&gt; '(0[1-9]|1[012])',&lt;br /&gt;        'day' =&gt; '(0[1-9]|[12][0-9]|3[01])'&lt;br /&gt;    )&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Parameters can be access like this:&lt;br /&gt;&lt;br /&gt;/controllers/controller.php&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function index(){&lt;br /&gt;    // params is stored in $this-&gt;params&lt;br /&gt;    $year = $this-&gt;params['year'];&lt;br /&gt;    $month = $this-&gt;params['month'];&lt;br /&gt;    $day = $this-&gt;params['day'];&lt;br /&gt;    &lt;br /&gt;    //&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-3152785486728264810?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/3152785486728264810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=3152785486728264810' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/3152785486728264810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/3152785486728264810'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/02/cakephp-routing-with-parameters.html' title='CakePHP Routing With Parameters'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-5862370678836145575</id><published>2009-02-13T23:35:00.003+08:00</published><updated>2009-02-14T00:49:27.548+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='large array'/><title type='text'>Increase Performance of Loop with Large Arrays</title><content type='html'>In PHP, this is how we usually loop through arrays:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;for ($i=0; $i&amp;lt;count($big_array); $i++){&lt;br /&gt; //&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Having this approach, program will try to count the $big_array every time it loops and it may cause some performance issues. To make it more efficient, we should code it this way:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;for ($i=0, $n=count($big_array); $i&amp;lt;$n; $i++){&lt;br /&gt; //&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It does the counting during initialization only.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-5862370678836145575?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/5862370678836145575/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=5862370678836145575' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5862370678836145575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5862370678836145575'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/02/increase-performance-of-loop-with-large.html' title='Increase Performance of Loop with Large Arrays'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-1115623195190516294</id><published>2009-02-13T03:01:00.002+08:00</published><updated>2009-02-13T03:06:45.398+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP 1.2'/><category scheme='http://www.blogger.com/atom/ns#' term='routes'/><title type='text'>How to Route Admin Actions in CakePHP 1.2</title><content type='html'>This is how to setup the routing:&lt;br /&gt;&lt;br /&gt;Router::connect('/admin/:controller/:action/*', array(&lt;span style="font-weight:bold;"&gt;'admin'=&gt;'true','prefix'=&gt;'admin'&lt;/span&gt;, 'controller'=&gt;'controller', 'action'=&gt;'action'));&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-1115623195190516294?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/1115623195190516294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=1115623195190516294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/1115623195190516294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/1115623195190516294'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/02/how-to-route-admin-actions-in-cakephp.html' title='How to Route Admin Actions in CakePHP 1.2'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-5100736385656834367</id><published>2009-02-12T23:24:00.004+08:00</published><updated>2009-02-12T23:38:12.639+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP 1.2'/><category scheme='http://www.blogger.com/atom/ns#' term='dropdown tree'/><category scheme='http://www.blogger.com/atom/ns#' term='generatetreelist'/><title type='text'>Indenting Tree List in Form Input Select using '&amp;nbsp;' as spacer</title><content type='html'>This is the scenario in cakePHP 1.2. &lt;br /&gt;&lt;br /&gt;In your controller, you have an action:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function add() {&lt;br /&gt; ... &lt;br /&gt; $categories = $this-&gt;Listing-&gt;Category-&gt;generatetreelist(null, null, null, '&amp;amp;nbsp;');&lt;br /&gt; $this-&gt;set(compact('categories','keywords','metros','states'));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;where '&amp;amp;nbsp;' is your spacer.&lt;br /&gt;&lt;br /&gt;Your view will have something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;...&lt;br /&gt;echo $form-&gt;input('Category');&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above combination will display a drop down menu with the '&amp;amp;nsbp;' printed as '&amp;amp;nbsp' and not as a space. So how would you do it in cakePHP 1.2?&lt;br /&gt;&lt;br /&gt;The key here is in the view file.&lt;br /&gt;&lt;br /&gt;instead of the above statement, you should have this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;...&lt;br /&gt;echo $form-&gt;input('Category', array('escape' =&gt; false));&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope this one helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-5100736385656834367?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/5100736385656834367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=5100736385656834367' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5100736385656834367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5100736385656834367'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/02/indenting-tree-list-in-from-input.html' title='Indenting Tree List in Form Input Select using &apos;&amp;amp;nbsp;&apos; as spacer'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-5223359745268527870</id><published>2009-01-29T00:30:00.004+08:00</published><updated>2009-02-12T23:52:51.180+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='merge array'/><title type='text'>Merging Arrays Preserving the Numeric Keys</title><content type='html'>Merging arrays like this:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$array1 = array();&lt;br /&gt;$array2 = array(1 =&gt; "data");&lt;br /&gt;$result = array_merge($array1, $array2);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;will result to:&lt;br /&gt;&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [0] =&gt; data&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Don't forget that numeric keys will be renumbered!&lt;br /&gt;&lt;br /&gt;If you want to completely preserve the arrays and just want to append them to each other (not overwriting the previous keys), use the + operator: &lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$array1 = array();&lt;br /&gt;$array2 = array(1 =&gt; "data");&lt;br /&gt;$result = $array1 + $array2;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;The numeric key will be preserved and thus the association remains. &lt;br /&gt;&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [1] =&gt; data&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://php.net/array_merge"&gt;http://php.net/array_merge&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-5223359745268527870?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/5223359745268527870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=5223359745268527870' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5223359745268527870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5223359745268527870'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/01/merging-arrays-preserving-numeric-keys.html' title='Merging Arrays Preserving the Numeric Keys'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-714061128134841605</id><published>2009-01-27T05:07:00.005+08:00</published><updated>2009-02-12T23:49:19.587+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP 1.2'/><category scheme='http://www.blogger.com/atom/ns#' term='empty options'/><title type='text'>Empty Options for cakePHP 1.2</title><content type='html'>$options['empty'], if set to true, forces the input to remain empty.&lt;br /&gt;&lt;br /&gt;When passed to a select list, this creates a blank option with an empty value in your drop down list. If you want to have a empty value with text displayed instead of just a blank option, pass in a string to empty.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php echo $form-&gt;input('field', array('options' =&gt; array(1,2,3,4,5), 'empty' =&gt; '(choose one)')); ?&amp;gt;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://book.cakephp.org/view/201/options-empty"&gt;http://book.cakephp.org/view/201/options-empty&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-714061128134841605?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/714061128134841605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=714061128134841605' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/714061128134841605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/714061128134841605'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/01/empty-options-for-cakephp-12.html' title='Empty Options for cakePHP 1.2'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-5977078556260174574</id><published>2009-01-27T02:52:00.001+08:00</published><updated>2009-02-12T23:48:05.223+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakePHP'/><category scheme='http://www.blogger.com/atom/ns#' term='javascript file'/><title type='text'>How to Include Javascript File in Cake PHP</title><content type='html'>If you want to use a Javascript file, you usually reference it in the head section of your layout:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;    &amp;lt;?php echo $javascript-&gt;link('script.js'); ?&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But sometimes you want to use a certain Javascript file only in one view. Then it doesn’t make sense to reference it in the layout. You could take the PHP statement from above and place it in your view, that will work. But it is not a clean solution as the Javascript reference is placed somewhere in the middle of the generated HTML code.&lt;br /&gt;&lt;br /&gt;Fortunately, CakePHP 1.2 allows you to define a reference to a Javascript file which is then added to the head section of the generated HTML code. For this purpose the variable $scripts_for_layout has to be added to the layout:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;    &amp;lt;?php echo $scripts_for_layout; ?&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the view you can now link to the Javascript file with:&lt;br /&gt;&lt;br /&gt;$javascript-&gt;link('script.js', false);&lt;br /&gt;&lt;br /&gt;Notice the second parameter. Set it to false to tell cake to put the reference in $scripts_for_layout variable in the layout file.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://cakebaker.42dh.com/2007/02/21/referencing-javascript-files/"&gt;http://cakebaker.42dh.com/2007/02/21/referencing-javascript-files/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-5977078556260174574?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/5977078556260174574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=5977078556260174574' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5977078556260174574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/5977078556260174574'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/01/how-to-include-javascript-file-in-cake.html' title='How to Include Javascript File in Cake PHP'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1371670590739165117.post-9100835848392959576</id><published>2009-01-27T02:42:00.002+08:00</published><updated>2009-02-12T23:51:15.763+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='if else'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><title type='text'>PHP Ternary Operator</title><content type='html'>Consider the following snippet of code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition){&lt;br /&gt; variable = value1;&lt;br /&gt;}else{&lt;br /&gt; variable = value2;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Instead of doing that way, we can just simply do it like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;variable = condition ? value1 : value2;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Another variation of using the ternary operator would be from:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition){&lt;br /&gt; echo "something1";&lt;br /&gt;}else{&lt;br /&gt; echo "something2";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And it can be expressed like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;echo condition ? "something1": "something2";&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can also nest the condition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;variable = cond0 ? (cond1 ? value1.1 : value1.2) : (cond2 ? value2.1 : value2.2);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Just use your imagination on how to use this form.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1371670590739165117-9100835848392959576?l=phpexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpexp.blogspot.com/feeds/9100835848392959576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1371670590739165117&amp;postID=9100835848392959576' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/9100835848392959576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1371670590739165117/posts/default/9100835848392959576'/><link rel='alternate' type='text/html' href='http://phpexp.blogspot.com/2009/01/php-ternary-operator.html' title='PHP Ternary Operator'/><author><name>Jun</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/40/167417879_acfab61249_o.jpg'/></author><thr:total>1</thr:total></entry></feed>
