In this section, you can walk through typical CakePHP applications to see how all of the pieces come together. Alternatively, you can refer to the non-official CakePHP plugin repository CakePackages and the Bakery for existing applications and components. CakePHP is a fast open-source platform for the development of the PHP framework. The objective of CakePHP is easy to create, distribute, and handle the web application. The CakePHP contains libraries, classes, and run-time infrastructure for creating web applications, which is inspired by the Ruby on Rails framework. It is based on the model–view–controller (MVC) approach that reduces the code length for creating a beautiful web application with less effort. The CakePHP language began in April 2005, when a Polish programmer, Michal Tatyarownikz, wrote a short report of a rapid application development framework in PHP and named it Cake. He announced that CakePHP is used as an open framework under the MIT license and opened it for the online community of developers. In December 2005, L. Masters and G.J. Woodworth established a CakePHP Software Foundation to promote development programs related to CakePHP and in May 2006 released the first version of CakePHP. Why we use CakePHPCakePHP has several features that make it highly recommended as a framework for quick and risk-free implementation of applications. CakePHP, the sweet cake. Ever you tested it? If not, then it is the time to test it’s sweetness. From this tutorial, I am starting new series of CakePHP. Progressively we will dig dipper into it, very fast. What is CakePHP? Let’s Run localhost/cakephp24 Make sure, you already run your apache and MySQL servers. What you see? Before explaining these colorful boxes, I think, we should get know with CakePHP folder structure. Yes, this is the long listing folder you will get when you open the CakePHP folder. One thing need to mention, you may not see .htaccess and other (.) files if you open through normal window. I am using Sublime Text as an editor. Normally, it shows everything inside the folder. Inside cakephp24 folder there are 4 folders.
Now let’s try to solve our colorful opening screen. The first two red boxes said that, we need to fix two security salts inside App/Config/Core.php. Open this file and replace the existing salt with some other secret text. /** * A random string used in security hashing methods. */ Configure::write('Security.salt', 'ShahjalalHossain'); /** * A random numeric string (digits only) used to encrypt/decrypt strings. */ Configure::write('Security.cipherSeed', 'ShahjalalHossain'); Greens are good. So, now go to the yellow boxes. It says, we need to configure our database from App/Config/database.php. Here you may not find this database.php file. Rather, you will find database.php.default. Rename this file to database.php. And, set the database info- class DATABASE_CONFIG { public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'root', 'password' => 'root', 'database' => 'cakedb', 'prefix' => '', //'encoding' => 'utf8', ); public $test = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'user', 'password' => 'password', 'database' => 'test_database_name', 'prefix' => '', //'encoding' => 'utf8', ); } Here, I have configured only default database. You have to create a database named cakedb. You can do it by phpMyAdmin. For this tutorial we will not need any table. Only database is ok. Now, go to your CakePHP welcome screen. What you see? All red and yellow has gone. Only green boxes are there. It is good, really good. Wait, except one yellow box. At this moment this yellow box is not our headache. Model for MVC class HelloWorld extends AppModel { } Controller for MVC class HelloWorldsController extends AppController{ public function index(){ } } Yes, a blank index function. We are almost set. View for MVC <h2>Hello World!!!</h2> Simple or what!!! Yes this is CakePHP. Now go to – localhost/cakephp24/HelloWords Conclusion Happy Coding… 🙂 Introduction to CakePHP Shahjalal Hej, I’m from Bangladesh. Learning programming is one of the freaking decisions I have taken in my life. Because, it makes me and my life crazy. I have great weakness on open source technologies. Perhaps, that’s why I do not know any closed source language. I fall in love with programming, when I started my undergraduate in East West University. Till now, I can not live without it. |