Friday, December 31, 2010

The minimum necessary site structure to run Yii

The minimum files and folder structure necessary to run Yii:
/index.php
/protected/components/controller.php
/protected/config/main.php
/protected/controllers/SiteController.php
/protected/runtime/
/protected/views/site/index.php
The minimum necessary configuration file is (/protected/config/main.php):
return array('import'=>array('application.components.*'));
SiteController.php should have this method:
public function actionIndex()
{
  $this->render('index');
}
That's it!


If you want use a layout, add:
/protected/views/layouts/main.php
/protected/views/layouts/column1.php
To enable gii, you need to add the /assets folder, and add this to your config:
'modules'=>array(
  'gii'=>array(
    'class'=>'system.gii.GiiModule',
    'password'=>'password',
    ),
),
For Model and Crud to work, you need to setup a db connection.

3 comments:

  1. This article may not the right place to post this question, but as you seem know lot about Yii I would like to get the answer for this question which I have posted in following forum.,

    http://www.yiiframework.com/forum/index.php?/topic/14752-passing-multiple-values-from-controller-to-view/page__p__73385#entry73385

    This is how to pass multiple objects from Controller to View, (actionCreate)


    and other question is how to attach multiple file uploads to a model without declaring field for each entry?

    http://www.yiiframework.com/forum/index.php?/topic/14754-multiple-file-uploads/page__p__73387#entry73387

    ReplyDelete
  2. @rasika

    1. to pass multiple objects from controller to view, just add them to the data array in the render function. when you pass 'model'=>$model, you can just add more items to that list.

    2. to allow multiple uploads to a model i would use an array. check the yii wiki for dealing with tabular input.

    ReplyDelete