Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Cakephp: How to cake bake all in Ubuntu 14.04?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 285
    Comment on it

    Cakephp's bake console is the fastest way to create models, view and controller. In order to create it first you need to create the table. In this case I am creating Users table:

     

    CREATE TABLE users (
        id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        username VARCHAR(50),
        password VARCHAR(255),
        role VARCHAR(20),
        created DATETIME DEFAULT NULL,
        modified DATETIME DEFAULT NULL
    );

    Now lets start with bake console, open terminal and go to the app directory of cakephp:

    $ cd /var/www/html/cakephp/app

    Lets start with cake bake with this command:

    amuk@amuk:/var/www/html/cakephp/app$ sudo ./Console/cake bake all

    Following output will be seen on your console:

    Welcome to CakePHP v2.7.11 Console
    ---------------------------------------------------------------
    App : app
    Path: /var/www/html/cakephp/app/
    ---------------------------------------------------------------
    Bake All
    ---------------------------------------------------------------
    Possible Models based on your current database:
    1. User
    Enter a number from the list above,
    type in the name of another model, or 'q' to exit  
    [q] >

    In my case I will type "1" for User and press Enter

     

    [q] > 1

    Baking model class for User...

    Creating file /var/www/html/cakephp/app/Model/User.php
    Wrote `/var/www/html/cakephp/app/Model/User.php`
    PHPUnit is not installed. Do you want to bake unit test files anyway? (y/n)

     

    Now press y for yes and press Enter. Following Output will be shown by the console

     

    You can download PHPUnit from http://phpunit.de

    Baking test fixture for User...

    Creating file /var/www/html/cakephp/app/Test/Fixture/UserFixture.php
    Wrote `/var/www/html/cakephp/app/Test/Fixture/UserFixture.php`
    Bake is detecting possible fixtures...

    Baking test case for User Model ...

    Creating file /var/www/html/cakephp/app/Test/Case/Model/UserTest.php
    Wrote `/var/www/html/cakephp/app/Test/Case/Model/UserTest.php`

    Baking controller class for Users...

    Creating file /var/www/html/cakephp/app/Controller/UsersController.php
    Wrote `/var/www/html/cakephp/app/Controller/UsersController.php`
    PHPUnit is not installed. Do you want to bake unit test files anyway? (y/n)
    [y] >

     

    Now again press y and hit Enter, following output will be shown:

     

    You can download PHPUnit from http://phpunit.de
    Bake is detecting possible fixtures...

    Baking test case for Users Controller ...

    Creating file /var/www/html/cakephp/app/Test/Case/Controller/UsersControllerTest.php
    Wrote `/var/www/html/cakephp/app/Test/Case/Controller/UsersControllerTest.php`

    Baking `index` view file...

    Creating file /var/www/html/cakephp/app/View/Users/index.ctp
    Wrote `/var/www/html/cakephp/app/View/Users/index.ctp`

    Baking `view` view file...

    Creating file /var/www/html/cakephp/app/View/Users/view.ctp
    Wrote `/var/www/html/cakephp/app/View/Users/view.ctp`

    Baking `add` view file...

    Creating file /var/www/html/cakephp/app/View/Users/add.ctp
    Wrote `/var/www/html/cakephp/app/View/Users/add.ctp`

    Baking `edit` view file...

    Creating file /var/www/html/cakephp/app/View/Users/edit.ctp
    Wrote `/var/www/html/cakephp/app/View/Users/edit.ctp`

    Bake All complete
    amuk@amuk:/var/www/html/cakephp/app$

     

    All done!. Now you will see Model, View and Controller for User has been made . On web interface go to "http://localhost/cakephp/users" and in my case I see page has been created where users will be listed and you can click on the "New User" menu to create new users. So you see how fast it is to create model, views and controller.

    Thanks for reading the blog

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: