Category Archives: CakePHP

Archive

Simple captcha component for CakePHP 2.x

Captcha-Component-for-CakePHP-2.x

Captcha-Component-for-CakePHP-2.x

Updated on – April 12, 2013

  • Random captcha images are possible. Set “theme”=>”random” in $settings variable of CaptchaComponent.php or in Controller when loading captcha component.
  • Can’t Read? Reload is possible now. A working piece of jQuery code is included in view file add.ctp. Be sure to include jquery library, such as https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js to make Reloading of captcha working

Updated on – April 09, 2013

Download Captcha Component for Cakephp 2.x
Download Captcha Component for Cakephp 1.x

How to make it working

Download attached zip file and extract. Copy all files placed in app folder to their corresponding locations. Continue reading

Category: CakePHP | Tags: , ,

Making now() date filter working and complex find conditions in CakePHP

Supplying complex find conditions in CakePHP can be tricky. I have got an example from my current project.

I wanted to list all auctions which are “not closed” and whose’ end date/time is greater that the current date/time. I can use the following statement. Continue reading

Installing PHPUnit in wamp in Windows7

Installing PEAR package manager

Add php directory to your Windows’ Environment Variables PATH, if it is not already added. My wamp php path is “C:\wamp\bin\php\php5.3.13″. Check Adding to Environment Variables Path if you are not sure how to add a value to Environment Variables Path in Windows 7. Continue reading

Setting id of input wrapper div in cakephp and hiding by default

It might be a simple thing for most of CakePHP pro’s but at the same time it could be a tricky thing for CakePHP newbies. I just caught one newbie CakePHP developer of my team spending time on figuring this out thus adding it here for future reference. I hope it helps someone else as well. Continue reading

How to get current theme name or theme working in cakephp

Making theme set and available by setting theme related properties in controller

Prior to cakephp 2.0

class UserController extends AppController {
    var $view = 'Theme'; //tells controller to use "ThemeView" class instead of the default "View" class
    var $theme = 'WhiteFeather'; //name of the theme folder which is supposed to be placed at views/themed/
}

Cakephp 2.0

class UserController extends AppController {
    public $viewClass = 'Theme'; //tells controller to use "ThemeView" class instead of the default "View" class
    public $theme = 'WhiteFeather'; //name of the theme folder which is supposed to be placed at View/Themed
}

Theme can be changed within a controller function or in beforeFilter/beforeRender by overriding the theme property:

$this->theme = 'BlackFeather';

You may want to know more about themes, here:
CakePHP 1.3 link http://book.cakephp.org/view/1093/Themes
Cakephp 2.0 documentation http://book.cakephp.org/2.0/en/views/themes.html

Category: CakePHP | Tags: ,

Conditional skip for a field from model validation in a cakephp controller

In a controller, a table field could be skipped from model validations by editing the “validate” property of a model. For example, i have a “date” validation for “dob” (date of birth) field set in my “User” model. Continue reading

A note on $form->dateTime(‘field_name’) generating offset warning in CakePHP

This is a note on $form->dateTime(‘field_name’) generating offset warning i.e. “Notice (8): Undefined offset: 1 [CORE/cake/libs/view/helpers/form.php, line 1836..“. If your “date” form field in a view is generating a similar warning you may need to look into the following scenario. Continue reading

A tip on CakePHP find list with related model conditions

You will need to add recursive=>(value) to the $params when you need to get a ‘list’ of table items using related model conditions.

Referring to the example depicted here, http://book.cakephp.org/view/1022/find-list let’s say you perform the following query: Continue reading

An example of Google Checkout Integration in CakePHP

NOTE: You will have to make changes into the component code in order to get it working with you application. This is only a sample component and it should not be taken as a plug-and-play kind of component.

NOTE: Download the latest Google Checkout library files from here. After downloading it from this link you will have to make changes to component code where you “include” vendors files following the new file naming structure Google have laid there. As an alternate, I have attached vendors/google files with the new zip archive (This is an OLD one, it’s when i did this) but i would strongly recommend the use of new google checkout library.

I am posting an implementation of Google Checkout payment gateway in CakePHP which i had implemented an year ago in one of my client’s website. The implementation was based on the use of vendors and components. I placed all google checkout files in “app/vendors” folder and created a component to process transactions. The file structure of vendor file was something like the following: Continue reading

Cakephp important facts you must know – Part 3

  • You load a plugin model like this: $this->loadModel(“Forum.Topic”)
  • You output requestAction result using $this->requestAction(array(‘controller’ => ‘articles’, ‘action’ => ‘featured’), array(‘return’)); // see array(‘return’)
  • Continue reading