Implementing MySql View in CakePHP For Typeahead Search

View works like a table, but it is not a table. It never exists; it is only a prepared SQL statement that is run when you reference the view name. A programmer can write VIEWs that limit the dataset both horizontally and vertically, ensuring that only the data that is required is queried for. Recently [...]

afterSave: A Great Callback Method for Soft Deleting Related Model Data( hasOne, hasMany, belongsTo)

Update: Here is model file to download Download Code I never like to “Hard Delete” data. Some one will make mistake deleting something. Then they will tell you retrive it. So “Soft Delete” can save you time telling you clients/boss why the data can not be retrieved. BTW “Soft Delete” means you keep a field [...]

Add Your Own Validation in model On CakePHP

Update: Here is model file to download Download Code CakePHP has many validation rules that can make model data validation much easier. There are 26 core validation rules. You can see here. These 26 rules almost covers all the validation. You can also add multiple validation to one field. But some time you need your [...]

Should I Use Database For Storing sessions in CakePHP?

Session handling is a important part of any web app. CakePHP offers 4 storage facilities for session storage. I will go through all of them and discuss advantages and disadvantages of 3 of them. They are cake (Saves the session files in your app’s tmp/sessions directory.), database(Uses CakePHP’s database sessions), php(The default setting. Saves session [...]

Prevent Your CakePHP App From XSS Attacks

By default Cakephp will protect app against SQL Injection if you use CakePHP’s ORM methods (such as find() and save()) and proper array notation (ie. array(‘field’ => $value)) instead of raw SQL. But this does not potect you from XSS attacks. To Understand XSS attack, i will show a simple example. Create a php code [...]

CakePHP and facebook SDK as Vendor

For most of the application on Facebook is simple but sometimes you have such a big application to develop you need to use a php framework. As I am a CakePHP developer, I like to use CakePHP for these type of applications .In this How-To, I will show how you can add Facebook SDK in [...]

Disable Browser Cache in Cakephp

When developing web apps, sometimes it is better to disable browser cache. We can do it in php by following code So how do we set these in cakephp? Very simple This will produce headers like this I recommend calling this function in certain function rather than calling it beforeFilter() function in app_controller.php

Adding Google’s Data APIs to CakePHP – include_path Problem Fix

I recently developed a web app with youtube api. In this app I submit comment on any video, like or favorite any video. I used the zend gdata library. So i put them in the vendor folder and add it to my the controller. But i found the famous include_path problem. So i will share [...]

Simple Way to Create Captcha in CakePHP

When i start developing site using CakePHP, I was at wits end about how to implement capcha. I found couple ways using google but all of them seemed hard to implement. Now i am going to show you can do it in an easy simple way.There are many ways to add captcha to your CakePHP [...]

Sweet Simple Caching with CakePHP

When you developing a website, more often than not you have small blocks of presentation code that need to be repeated from page to page. In CakePHP they have Elements to help you with it. It’s all very fine but when you have to pull data from database and show it on the element the [...]