Thursday, April 11, 2013

Step By Step Setup YiiBoilerPlate


Yii Boilerplate Installation Guides:

1. Download YiiBoilerplate from https://github.com/clevertech/YiiBoilerplate

2. Map admin.domainname.com (or similar) to backend > www
   Map domainname.com (or similar) to frontend > www (if required)

3. Create database for app
   Create database for test with suffix _test (if required)

4. Add db details to common > config > params-local.php

5. Remove comments from db connections in console > config > main.php
   Remove comments from db connections and gii in backend > config > main.php
   Remove comments from db connections in frontend > config > main.php (if required)

6. Run the following command
   ./runpostdeploy local non-migrate
   ./yiic migrate

Yii Boilerplate Get Start:

** Please chmod 777 for the following file and folder
- yiic and runpostdeploy
- backend/views
- backend/controllers
- backend/models

1. Run the following command to create table in mysql
   ./yiic migrate create create_tablename

2. Goto folder console/migration/ and find the file to add in table stucture

3. Run the following command after edit migration file
   ./yiic migrate

4. Goto backend/config/main.php to uncomment Gii section and save the file

5. You can browse Gii with the following path and start work with your MVC
   http://xxx.dev/backend/www/gii/default/index

To Enable Gii

1. Goto backend/config/main.php

2. uncomment Gii

3. Add the following code in Gii section, else you will get error 403
   'ipFilters' => array('127.0.0.1', $_SERVER['REMOTE_ADDR']),

To Browse Gii

1. Goto http://yourdomain.com/backend/www/gii/model/


*********************  HAPPY CODING!! ******************

34 comments:

  1. ok found the file mlXXXXXX_XXXXXX_create_tablename.php

    and? how it would be edited? that info unfortunely is not in the yiiboilerplate documentation.

    ReplyDelete
  2. Hi Nestor, its depend on what sql queries you want to write. The following is the sample of creating table, hope it is helping:

    class mlXXXXXX_XXXXXX_create_tablename extends CDbMigration {

    public function up() {
    // Create sample table
    $create_fields = array(
    'id' => 'INT NOT NULL AUTO_INCREMENT',
    'text' => 'TEXT NOT NULL',
    'sequence' => 'INT NULL',
    'status' => 'TINYINT NULL',
    'create_date' => 'INT UNSIGNED NULL',
    'user_id' => 'INT UNSIGNED NULL',
    'PRIMARY KEY (id)'
    );
    $this->createTable('sample', $create_fields);
    }

    public function down() {
    //drop question_table
    $this->dropTable('sample');
    }
    }

    ReplyDelete
  3. The concept to create table with migration command in regular yii framework are the same. The only difference is the folder location, it located in protected/migrations .

    ReplyDelete
  4. I like the tutorial, was a big help. You're cute btw ;)

    ReplyDelete
    Replies
    1. Hi Jamarcus, Thanks for the support. ^^

      Delete
  5. Really great tutorial, straight steps to follow and project is ready to deploy.

    Many thanks.

    ReplyDelete
  6. Hello,

    I have created two virtual host in my ubuntu 12.10 os. i.e

    backend.local for yii backend and
    frontend.local for yii frontend

    I have added path for them in my vhost like:

    ServerName backend.local
    DocumentRoot /var/www/yiibootstrap/backend/www

    and

    ServerName frontend.local
    DocumentRoot /var/www/yiibootstrap/frontend/www

    But when I am trying open

    http://backend.local/gii

    its showing me following error:

    Not Found

    The requested URL /gii was not found on this server.

    Please help to solve this. I am very new in yii framework.

    Thanks

    ReplyDelete
    Replies
    1. Please check if you had enable gii module from backend\config\main.php

      Delete
    2. Yes gii module is enabled here. I have removed comments these lines:

      'modules' => array(
      'gii' => array(
      'class' => 'system.gii.GiiModule',
      'password' => 'clevertech',
      'generatorPaths' => array(
      'bootstrap.gii',
      //'ipFilters' => array('127.0.0.1', $_SERVER['REMOTE_ADDR']),
      ),
      )
      ),

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Please try with this:

      'modules' => array(
      'gii' => array(
      'class' => 'system.gii.GiiModule',
      'password' => 'clevertech',
      'ipFilters' => array('127.0.0.1', $_SERVER['REMOTE_ADDR']),
      'generatorPaths' => array(
      'bootstrap.gii'
      )
      )
      ),

      Delete
    5. Thanks for reply..but its still not working

      Delete
    6. How about http://backend.local? Any error?

      Delete
    7. Hi,

      I solved that error :) It was the issue of read-write module in my ubuntu os. by the way Thanks for help. Can I ask you little more help about YiiBoilerPlate ? Do you have some tutorials on it?

      Delete
    8. that's great to hear that and have fun with boilerplate! (^-^)

      Delete
  7. Hi Lee, Thanks a lot for the tutorial. This helped me a lot. Have you tried running unit test. test.php is in frontend config and do we create test in frontend or in tests folder?

    ReplyDelete
  8. 1./When run (runpostdeploy local non-migrate), I get bug:
    Running command:
    php 'C:\wamp\www\yiiboilerplate\common\lib/../../yiic' migrate --interactive=0 'php' is not recognized as an internal or external command, operable program or batch file.
    2./When run (yiic migrate), I get bug:
    PHP Error[2]: PDO::_construc<>: php_network_getaddresses: getaddrinfo fail: No such host is know
    in file c:\.......\common\lib\CDbConnection.php at line 422

    ==> Please help me setup detail!

    ReplyDelete
    Replies
    1. It could be your db setting error, or try to restart mysql service.

      Delete
    2. Can you vnc remote and config for me, please? Thank you very much :). My yahoo, skype: quangckt

      Sory about my bad english!

      Delete
  9. How can use gii to create/update models in the Common directory?

    ReplyDelete
    Replies
    1. Hi Jan, you can try to create from Backend then move the file to Common Directory

      Delete
    2. Just change the Model Path
      from application.models
      to common.models

      Delete
  10. Hi Jan,there is no such file named params-local.php in the newest YiiBoiler.Do I need to create one?

    ReplyDelete
    Replies
    1. You are right. I am too looking into this setup but could not find this file. I guess the structure mentioned in this article has changed in the last few months base don the commits I see on git.

      Delete
  11. Hi lee, I can't configure my yii boilerplate application. can you give me some details about your each step??

    1. Map admin.domainname.com (or similar) to backend > www
    Map domainname.com (or similar) to frontend > www (if required)
    mean what??

    2. Run the following command
    ./runpostdeploy local non-migrate
    ./yiic migrate

    how to run these commands??

    ReplyDelete
    Replies
    1. If you are using LAMP environment, you should go to /etc/httpd/vhosts.d to setup the mapping. Then cd /var/www/hosts/ and redirect to your project folder.

      To run migration command, you have to go to your project folder from command prompt.

      Delete
  12. This comment has been removed by the author.

    ReplyDelete
  13. I run these commands but i get the error that '.' is not recognized as an internal or external command.

    ReplyDelete
  14. And i am working on WAMP environment.

    ReplyDelete
  15. Great work, I would mention a addition of a line indicating that after unpacking the archive a dependency installation should be done with composer.
    But I still have some questions.
    1. Using Gii I create models, but when using crud the controllers are created descended from CController, is it right to be changed to BackendController (for backend for example)?
    2. Even changed to "extend BackendController" in a created controller i get a wrong view in browser? Is there any specific things for creating mvc with crud?

    ReplyDelete
  16. Great,
    and how do I post production.
    I have FTP access to public_html.

    ReplyDelete
  17. How can it be configured on production server if everything is uploaded in public_html. So i am getting issue if i am pointing public_html/frontend/www its always redirecting to index.php means its always redirect to default controller it does not process the request of other controller.

    Please guide on this.

    ReplyDelete