Skip to main content

Posts

Showing posts with the label CakePhp

Simple CRUD Example in Cakephp

Simple CRUD Operation in CakePHP 2.x This tutorial will explain about CRUD Operation in CakePHP. Here we will perform mysql Insert, Select, Update, Delete operation in cakePHP Framework. As we know CakePHP uses MVC design patterns. Here we will cover following points: 1. MySQL Database Table Used 2. We are using CakePHP Version 2.x 3. Create/Select/Update/Delete records. We have assume that you have already created you database table. Here is simple users table structure. CREATE TABLE `users` (   `id` bigint(20) UNSIGNED NOT NULL primary key AUTO_INCREMENT,   `firstname` varchar(128) NOT NULL,   `lastname` varchar(128) DEFAULT NULL,   `username` varchar(128) DEFAULT NULL,   `password` varchar(128) DEFAULT NULL,   `email` varchar(128) DEFAULT NULL,   `created` datetime DEFAULT NULL,   `modified` datetime DEFAULT NULL, ) Create action inside Users controller. Controller: app/Controller/UsersController.php Create add functi...

CakePHP Interview Question and Answer

CakePHP Interview Question and Answer What is the first file that gets loaded when you run a application using cakephp? Answer: bootstrap.php     You can be changed it either through index.php , or through .htaccess     How to change via webroot > index.php         if (!defined('CAKE_CORE_INCLUDE_PATH')) {         if (function_exists('ini_set')) {             ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));         }         if (!include('Cake' . DS . 'bootstrap.php')) { // Change bootstrap.php file to any file name             $failed = true;         }     } else {         if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {             $failed = true;     ...

My CakePHP 3 Review

My CakePHP 3 Review – Still Fresh, Still Hot This past month, the  CakePHP  team announced the launch of the alpha release of  CakePHP 3 . The Cake development team considers version 3 to be a game changer, so with the alpha release of version 3 now hot out of the oven, this article takes a fresh look at CakePHP 3 as an effective modern framework for PHP development. A Brief History These days, there are so many options when it comes to  PHP development . As PHP has matured, more and more PHP Frameworks have come onto the scene, providing developers with a wide array of choices. But it hasn’t always been that way. Back in 2005, when PHP 4 was still the standard, there were no PHP frameworks and developing an object oriented coding approach in PHP was certainly a challenge. It was then that CakePHP emerged – the first-ever PHP  MVC  framework. In the nearly 10 years that have passed since it was first released, CakePHP has continued to ev...

Cakephp Model Attributes

useDbConfig: The useDbConfig property is a string that specifies the name of the database connection to use to bind your model class to the related database table. Example usage: class Example extends AppModel {     public $useDbConfig = 'alternate'; } useTable: The useTable property specifies the database table name. class Example extends AppModel {     public $useTable = false; // This model does not use a database table } Alternatively: class Example extends AppModel {     public $useTable = 'exmp'; // This model uses a database table 'exmp' } Order The default ordering of data for any find operation. Possible values include: $order = "field" $order = "Model.field"; $order = "Model.field asc"; $order = "Model.field ASC"; $order = "Model.field DESC"; $order = array("Model.field" => "asc", "Model.field2" => "DESC"); virtualFields Array of virtual fields this model h...

Cakephp Html Helper

Meta Tag <? php   echo   $this -> Html -> charset ();   ?> Will output: < meta   http - equiv = "Content-Type"   content = "text/html; charset=utf-8"   /> Link Tag <? php   echo   $this -> Html -> link (      'Delete' ,      array ( 'controller'   =>   'recipes' ,  'action'   =>   'delete' ,  6 ),      array (),      "Are you sure you wish to delete this recipe?" ); ?> Will output: < a   href = "/recipes/delete/6"   onclick = "return confirm('Are you sure you wish to delete this recipe?');" > Delete </ a > Creating Table header <?php   echo   $this -> Html -> tableHeaders (      array ( 'Date' , 'Title' , 'Active' ),      array ( 'class'   =>   'status' ),   ...