Archive for "CakePHP"

Sep
16
Croogo – A free open source CakePHP powered CMS for PHP

Croogo is a free web based CMS (Content Management System) for PHP built on the top of CakePHP MVC framework. It was first released on October 07, 2009 by Fahad Ibnay Heylaal. It’s latest version is Croogo-1.3.2 and it could be downloaded here. Click to continue »

Share

Tags : , ,

Sep
15
New improved CakePHP cookbook documentation

Gone are the old days when CakePHP developers would complain about the in-sufficient documentation available in CakePHP. CakePHP community has not only improved existing documentations but going a step further they have added separate tabs for all three main versions (1.1, 1.2, 1.3) to make it easy for the readers to switch into one version and another. Click to continue »

Share

Sep
15
CakePHP 1.3.4 released, 2.0 on the way!

The CakePHP core team announded the release of CakePHP 1.3.4 recently (on Sep 12, 2010). It was almost within month since the last CakePHP release i.e. 1.3.3. The team announced that there had been a few changes which could affect applications built in 1.3.3. Click to continue »

Share

Tags : , ,

Sep
15
Use of custom displayField paramater in CakePHP

The $this->displayField is used to define custom display field while doing ‘list’ or scaffolding in CakePHP. It can be specified either in Model class or just before making a db call. Click to continue »

Share

Tags : , ,

Sep
15
Using Inflector singularize and camelize for taking out model name in CakePHP

We can use CakePHP library’s Inflector::singularize() and Inflector::camelize() methods for taking out corresponding model name from a controller name (provided we follow CakePHP’s naming conventions well). Click to continue »

Share

Tags : , , ,

Sep
14
Security component black hole, form submit dies on a blank page with no error

The problem started when i used Auth component in my current CakePHP project. Everything seemed working fine until i created an html form, submitted it and tried to retrieve this form’s data in controller action. I tried to print $this->data in controller action but it showed nothing and ended on a blank white page (which is called “blackHole” in Security component’s language). Click to continue »

Share

Tags : , , , ,

Aug
20
Fix to jQuery plugin does not work on ajax loaded content

I had been loading table records through ajax pagination using jquery. Some of the urls/links (View Details, Edit and Delete) in loaded content had been using thickbox to handle respective requests. Although, if i did’t use the ajax to load records these links would work fine and thickbox would open. But once i introduced ajax they suddenly stopped working. Click to continue »

Share

Tags : , , , ,

Jul
01
Cakephp pagination and custom named arguments handling

Let’s have a look at the scenario first.

I have a “contacts” controller, a “display” action in it(controller) and a view “display.ctp” to show results. As normal my “display” action lists all the contacts by calling $this->set(‘contacts’, $this->paginate(‘Contact’)) inside the controller action “display”. The view works normal. Click to continue »

Share

Tags : , , ,

Jun
05
Creating Ajax form in Cakephp using jQuery

Because of its being more flexible, extensible and precise nature the jQuery certainly has emerged as a more popular Javascript library as compared to prototype library. If you plan your Cakephp application depend heavily on Javascript, its right time to chose jQuery for your cakephp-cum-javascript needs. Click to continue »

Share

Tags : , ,

May
07
Simple captcha component for CakePHP (New)

Updated on – December 23, 2011

Download files

Follow these simple steps to make it working. (I assume that someone trying it has proficient knowledge of CakePHP framework. I may or may not help in problems which are related to knowledge of CakePHP rather than component itself).

Copy attached font file (monofont) to ‘webroot’ folder.

Copy component file (captcha.php) to app/controllers/components

Create a function similar to the following in your controller. (NOTE: I have used “signups” controller for demonstration purpose only. You should change controller name accordingly.)

	function captcha()	{
		$this->autoRender = false;
		$this->layout='ajax';
		if(!isset($this->Captcha))	{ //if Component was not loaded throug $components array()
			App::import('Component','Captcha'); //load it
			$this->Captcha = new CaptchaComponent(); //make instance
			$this->Captcha->startup($this); //and do some manual calling
		}
		//$width = isset($_GET['width']) ? $_GET['width'] : '120';
		//$height = isset($_GET['height']) ? $_GET['height'] : '40';
		//$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
		//$this->Captcha->create($width, $height, $characters); //options, default are 120, 40, 6.
		$this->Captcha->create();
	}

Call the captcha action from within your img tag in the view file as below:

echo $form->create("Signups");
echo $html->image($html->url(array('controller'=>'signups', 'action'=>'captcha'), true),array('style'=>'','vspace'=>2)); ?>
echo 'Enter the given security code:';
echo $form->input('Signup.captcha',array('autocomplete'=>'off','label'=>false,'class'=>'','error'=>__('Failed validating code',true)));
echo $form->submit(__(' Submit ',true));
echo $form->end();

And you are done! The captcha image should look like Cakephp Captcha COmponent

Also, you can re-generate the captcha by adding (replacing code in line 2 of the above) ajax code something similar to the following:

<div id="captchaID" ><?php
echo $html->image($html->url(array('controller'=>'signups', 'action'=>'captcha'), true),array('style'=>'','vspace'=>2)); ?></div>
<?php echo $ajax->link('Can not read this code? Reload.','regenerate code',array('url'=>'reload_captcha','update'=>'captchaID')); ?>

In the code above it calls a reload_captcha function of the current controller. You can place reload_captcha in current controller or preferrably in the app_controller to make it available universally. Here’s the code:

	function reload_captcha()	{
		App::import('Component','Captcha'); //load it
		$this->Captcha = new CaptchaComponent(); //make instance
		$this->Captcha->startup($this); //and do some manually calling
		$this->layout='ajax';
		Configure::write('debug',0);
		$this->viewPath = 'elements'.DS;
		$this->render('reload_captcha');
	}

Obviousaly it renders a reload_captcha element. So create a reload_captcha.ctp file and place it in views/elements with the following code in it:

<?php echo $html->image($html->url(array('controller'=>'signups', 'action'=>'captcha'), true),array('style'=>'','vspace'=>2)); ?>

There is model validation code included in the files with example of how to validate it. Files include a model with new validation entry along with two function.

You can see it in working here. Let me know if you discover any issue while implementing it. Your suggestions to improve it are always welcome.

Download files

Share

Tags : , ,

Freelance Jobs