Thursday, 19 May 2011

CakePHP - Matching Multiple Checkbox Inputs With Join/Cross Tables Without Magic

Given the situation: A `trainee` wants to select available time for courses. We have Table `days` and Table `sessions`, having a join table `days_sessions`. Each `days` may have 3 `sessions`, and  can select multiple `days` in the form. In the end, we end up with another join table like `trainees_days_sessions`

1. We have predefined data in `days_sessions`, e.g. Monday morning - 'MonM', Tuesday night - 'TueN', etc.
2. In the form we have checkboxes for each `days_sessions`. We may code it as

Input type='checkbox' id='data[DaySession][DaySession][]' name='data[DaySession][DaySession][]' value='*'/

Note that the `id` must be coded in such a way of data[model_name][model_name][] (as defined in your model), while the value (* sign) must be the `id` column in `days_sessions` table.

Thursday, 12 May 2011

Bake Cake MySQL error

If you have come across to warnings like
Warning: mysql_connect(): [2002] No connection could be made because the target machine actively in ...cake\libs\model\datasources\dbo\dbo_mysql.php on line...
PHP Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in ...cake\libs\model\datasources\dbo\dbo_mysql.php on line ... 
And etc. Can try the following solution below:

1. Open php.ini
2. Look for the mysql.default_port, set it to the number accordingly, e.g.
mysql.default_port = 3306 

Fatal Error While Baking Cakes

Fatal error: Call to undefined function mysql_connect() in C:\...\cake\libs\model\datasources\dbo\dbo_mysql.php on line 600'
If you are using easyphp and have met this fatal error when baking cakes, can try this:
1. Copy php.ini from [easyphp]\apache to [easyphp]\php.

Reference:
Look for reply from andrej

Bake Cake with PHP in windows

In my case, i am using Windows 7.

1. Open cmd
2. CD to php directory
e.g. c:\program files\easyphp\php
3. Bake the cake using php.exe.
e.g. c:\program files\easyphp\php\php.exe "c:\[your localhost+project name]\cake\console\cake.php" bake
4. Start baking the cake!

Reference:
http://kodegeek.wordpress.com/2009/06/13/how-to-bake-on-windows-xampp-environment/

Tuesday, 10 May 2011

First Attempt With CakePHP

Currently learning from the IBM tutorial:
Cook up Web sites fast with CakePHP, Part 1: Getting started

I am using easyphp, and is go to set up the new cake as a production installation.

Several important steps:
1. In httpd.conf, set document root to:
DocumentRoot "${path}/www/cakephp/app/webroot" 


2. Also in httpd.conf, also set document root directory to
Directory "${path}/www/cakephp/app/webroot" 
...
 AllowOverride All
...


3. Setting up the database configuration:
Copy and rename the "app/config/database.php.default" into "app/config/database.php" and edit accordingly.


4. Create a user model:
 Create the file as "app/model/user.php" (or whatever name, as long as know how to handle)


5. Create a register view:
Create the file as "app/views/users/register.ctp


6. Create a controller and register action:
Create the file as "app/controller/users_controller.php". 



7. Bake it:
Go to the url: "http://localhost/users/register". 

Monday, 9 May 2011

CakePHP, EasyPHP and mod_rewrite

For a standard EasyPHP package, mod_rewrite is off in httpd.conf.
As using CakePHP requires the mod_rewrite, we will need to modify the httpd.conf of EasyPHP by just, uncomment it.

#LoadModule rewrite_module modules/mod_rewrite.so -> remove the hash

Tuesday, 3 May 2011

Switching Back To Opera Again

Since switching over to Chrome 15 months ago, now finally come back to Opera.

Opera 10 series, for me is quite a failure which contributes to the switch over, particularly in web compatibilities and extremely slow javascript execution speed as compared to chrome. (Or maybe i should say it is the result of following the protocols and procedures 100%?)

But now, Opera 11 is just as nice as Chrome, so it's time for me to come back to Opera again.

A major weakness for both web browsers:

Chrome 10: Sometimes will still crash when visiting some websites that contain flash applications.

Opera 11: Speed is still lacking a bit compared to chrome, but is very much faster than opera 10.

And don't ask/suggest me to use IE or Firefox unless they are proven...