Monday, May 25, 2009

CakePHP - Pagination

I've spent quite sometimes looking for this information, after lots of trial and errors I've found the solution.

If you want to know what is the param to be inserted in
$paginator->prev("Previous", null);

The second parameter has to be like below:
array("url"=>array("limit:".$limit)), url is fixed. In the array "name_of_param":"value_of_param"

If you have dynamic limit in your page, and you want to maintain it when you click on Previous or Next. This is the solution you need.

By the way, if your CakePHP is not up to date (like mine), when you want to do a toggle sort for your TH, the default function might not work. Update your pagination.php to this version:

Then you'll be able to toggle this sort('Name', 'name')?>

Good luck!

Sunday, May 3, 2009

CodeIgniter - Removing index.php by Changing .htaccess and httpd.conf

I've done this many, many times. But whenever I setup a new site on a new developer machine, I will have to do research over and over again. I decided to write down the details, actually only a few steps.
  1. Remove the index.php in the CI config file
    $config['index_page'] = "";

  2. Add .htacess file in the root of your application
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  3. Uncomment the mod_rewrite in httpd.conf
    LoadModule rewrite_module modules/

  4. Change None to All
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all

  5. As well as the web root folder (this is needed)
    <Directory "C:Apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
And done!