Monday, 27 May 2013

Creating Controllers, Models, Views with the help of CakePHP console commands

In the previous tutorials of cakephp we seen that we were manually writing the code for each part like for creating controller we were first extending the class with AppController and for creating a model we were extending the class with AppModel Today I will show you how you can create MVC using simple console commands that will be really helpful for you in future so let's get Started .

->> First of all create a database and put a simple table inside this database e-g For example if you are creating a students entry system name the table students as the CakePHP naming convention you have to use plural name for every table and it's necessary.

->> Now setup CakePHP environment if you don't know how please visit this tutorial . Installing and Running CakePHP

->> Now after configuring everything you just have to sit relax and take a cup of coffee or something and just follow from onwards here :-)

->> In the Environment Variable Set The Path to C:\xampp\htdocs\student_entry\app\Console and put semicolon after that and also this one so complete format is like this (Note only for Xampp Users).


and save it. :-) 

->> now to check whether cake is working write cake in cmd as shown in screenshot the following message will be displayed. 

->> if some errors are shown it means you have made some mistake well try again and fix what mistakes you have done in giving path.

->> now suppose your application name is students_entry what you have to do is in console write

cd c:/xampp/htdocs/students_entry/app

(if you have some other name then replace it with your name)

->> now just write cake bake and you will be presented with following screen 

->> For creating Views just write V for Controller write C etc and so on and the rest of the process is straight forward.

->> Just create views models and controllers for your database and it will automatically generate everything for you.

->> Now go to your browser and write localhost/student_entry/students/add and you will be provided a complete application.

Hope so you liked this tutorial for any query please leave comment so I can know. Share it with your friends please .


Post a Comment

Enter your Comments about this post