YII framework configuration

Sunday, December 20th, 2009

I’m toying with the Yii Framework for some time now and even if i cost me a lot of anger and frustration in the beginning I’m starting to like it more and more, alas I do have to say that the documentation isn’t always that clear and for someone who begins or who’ll write some large applications the configuration file can be a hassle so here’s my solution:

Brake down the configuration file in multiple files, this will give you some speed disadvantage and some will  saying that I’m raping Yii framework purpose for speed but at least to me it seems more clear

This is the protected.config/main.php

dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'WEBSITENAME',
'modules'=>array(
'users'=>array(
//sub modules in the module users
'modules'=>array(
'messaging',
'profile',
'dashboard',
)
),
'about',
'forums',
),
// preloading 'log' component active loading
'preload'=>array('log'),

// autoloading model and component classes lazy loading
// I make the difference between CformModel and CActiveRecord
'import'=>array(
'application.models.*',
'application.models.forms.*',
'application.models.database.*',
),

// application components
'components'=>array(
// enable cookie-based authentication
'user'=>array('allowAutoLogin'=>true),

// data relinquished to database.php
// for easy access and usability as also for the future
// installation procedure, it's less to write to a file
'db'=>include(dirname(__FILE__).'/database.php'),

// for a better overview we exculded url routes to a seperate file
'urlManager'=>include(dirname(__FILE__).'/routes.php'),

//authentication component needs data from db for CdbConnection
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
'defaultRoles'=>array('authenticated', 'guest'),
),

//security measures
'request'=>array(
'enableCsrfValidation'=>true,
'enableCookieValidation'=>true,
),
),

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
// uncomment the following if you want static params in the application
//'params'=>array(include(dirname(__FILE__).'/params.php'))
);

database.php

'CDbConnection',
'connectionString'=>'mysql:host=localhost;dbname=mysql',
//'connectionString'=>'pgsql:host=localhost;port=5432;dbname=mysql',
'username' => 'root',
'password' => '',
);
?>

routes.php

'path', // path or get
'urlSuffix' => '', //.html .whateverextentionyouwant
'showScriptName' => true,
'rules'=>array(
'users/recovery/perimeterSecurity/'=>'users/recovery/perimeterSecurity',
),
);
?>

param.php

//nothing in it at the moment

CodeIgniter the views and .htaccess

Saturday, March 14th, 2009

I must admit that I not a huge fan of Frameworks and Patterns because:

A) They make things complicated

B) Subject you to some nasty code stuff and rules

C) Because templating and Frameworks can be water and fire.

Codeigniter on the opposite has some advantage on it side for the templating stuff. This is really a short explanation for a common problem in other framework.

What to do if you want a nice folder structure or have different template styles, remember this is just a basic thing which happen to work in CI 1.7.


function index(){
$this->load->view('Themename/news/index);
}

Just add some slashes an it works so normally it should work if you would make an adaptation for themes too with a variable in it.

The next thing was kind of hard to find on the web so let me share it. It’s for when you develop with CI and your not working in the root directory of your server.


DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

MVC again

Monday, March 9th, 2009

I’ve grew bored of having to deal with some irritating PHP issues so I’ve turned my back to those and began testing codeIgniter. It seems strait forward but templating already has me intrigued with problems and mod_rewrite needs a look too I think :p .

Cakephp

Saturday, November 1st, 2008

Begin this week I began to experiment with cakephp but there’s a downside, Cake is something like rails but unfortunately the framework has less good tutorials.

About Me

Here I'll share my knowledge, discovery and experience related to my hobby and work. Most articles on this site are related to blog design, short reviews, tips and make money online. More

Find entries :