This text is replaced by the Flash movie.

Archive for the ‘CakePHP’ Category

Two Versions Cake Console

January 13th, 2012
Cake 2.0 was recently release, but I don't want to migrate yet some applications I already build with this version (afraid there are so many changes) most of my work are under 1.3, so I just decided to study it first. To have 2 cake console what I did is just to add another path in environment variables, Cake 2.0 console path is at cakephp/app/console and just rename cake.bat to cake2.bat, now I can use 2 cake versions within my current PC system. 

Cake Console 2.0

PNG upload/resize trouble

September 25th, 2010
While updating a component I got from cakePHP (Image Resize/Upload) I found out that it was not for my current version of PHP - it has trouble uploading PNG type image, I'm getting "Warning (2): imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error" This error only occur on servers with PHP v5.1.x or newer... so the simple solution from the code...

from
imagepng($cropped,$filename,80);
to
imagepng($cropped,$filename,8);

The third parameter is for the quality of the image to be uploaded so for png it only supports from 0 - 9, above that it will cause warnings and errors.

Cake using Multiple Select Checkboxes

December 2nd, 2009

A sample on how to use multiple select checkbox within cakephp views and controller.

 

After reviewing the http://api.cakephp.org/file/cake/libs/view/helpers/form.php#method-FormHelperselect


1.) Inserting to database

-View Decleration Example.

1
2
3
4
5
6
7
8
9
10
11
 <?php 
//add.ctp for example
?>
     <em>How would you describe your job (mark as many as applies):   </em>
           <?php       echo $form->input('describeJob', array('label' => false,
                                                    'div' => false,
                                                    'type' => 'select',
                                                    'multiple'=>'checkbox',
                                                    'legend' => 'false',
                                                    'options' => array('Physical' => 'Physical','Mental' => 'Mental', 'Stressful' => 'Stressful',  'Easy-going' => 'Easy-going', 'Secure' => 'Secure', 'Non-secure' => 'Non-secure', 'Exhausting' => 'Exhausting', 'Relaxing' => 'Relaxing' )
                                                      )); ?>

-On your controller. Use implode php function and add a seperator that you like, for this example I use ","

1
2
3
4
5
6
 <?php 
 //job_controller @add() function
        if (!empty($this->data)) {
        $this->data['Job']['describeJob'] = implode(",",$this->data['Job']['describeJob']);
                $this->Job->create();
?>


2.) Editing part, Retrieving values of the datafield to mark check on those were choosen before. 
-View Decleration Example. In this example I used explode function of php directly in the view, notice the "selected" option added in to the $form->input helper, this will get the values, supposed to be check in that field.

1
2
3
4
5
6
7
8
9
10
<?
//edit.ctp for example
       $piecesJob = explode(",",  $this->data['Job']['describeJob']);
             echo $form->input('describeJob', array('label' => false,
                                                    'div' => false,
                                                    'type' => 'select',
                                                    'multiple'=>'checkbox',
                                                    'legend' => 'false',
                                                    'options' => array('Physical' => 'Physical','Mental' => 'Mental', 'Stressful' => 'Stressful',  'Easy-going' => 'Easy-going', 'Secure' => 'Secure', 'Non-secure' => 'Non-secure', 'Exhausting' => 'Exhausting', 'Relaxing' => 'Relaxing' ),
                                                    'selected' => $piecesJob   )); ?>

That's it :)

Cake Baking Models – Cannot see other tables

November 7th, 2009

Problem.
After I updated the database, I added 1 table; relate it to another table, and go to the command line to bake what I did, after typing "cake bake model" at the command prompt, I found out that the recently added table was not listed.

Cake PHP Bake Model Problem

 

Reason.
Cake caches your model schema. 

Solution.
1.) 
Clear your cache by deleting all files in your app's tmp/cache/models/
and tmp/cache/persistent/

2.) 
Disable caching in your app's config/core.php // make sure to enable back again in production setup

/**
 * Turn off all caching application-wide.  *  
 */  
Configure::write('Cache.disable', true);

After doing the solution, I can now successfully bake the new table.