Easy Config - main.php

In the process of working with (learning) the Yii Framework, I spent the entire day yesterday trying to track a bug that broke the Automatic Code Generation module. I created several new databases, and kept having the same problem. As it turns out the problem ended up being a misplaced configuration item that I had added at some point during the process. Because of the multi-level nested arrays sometimes four or five levels deep, it is easy to misplace a new item within the hierarchy, particularly if you are new.

Here’s the SOLUTION :

http://www.journey-of-flight.com/bh_zend/Yii_FrameWork/easy_config/index.php

Hope this is useful,

Bill Hernandez

Plano, Texas

I have to disagree on your alternative way being easier to read: it looks like it take 3 times as many lines of code to do the same thing.

I think if you do these two things, the default way is just fine:

  1. Use the tab character for indenting, and keep things properly indented at all times.

  2. Use a good code editor so that when you put your text cursor (the blinking line, whatever you call it) next to a bracket, it highlights the corresponding bracket. This helps find errors in where your brackets/parentheses begin and end. Most of the high-end code editors support this.


<?php

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Razmer Car Parts',

	'timezone'=>'UTC',

	

	'preload'=>array('log'),


	'import'=>array(

		'application.models.*',

		'application.models.shared.*',

		'application.models.shared.image.*',

		'application.components.shared.*',

		'application.components.*',

		'application.components.shared.imageGallery.*',

		'ext.mail.Message',

		'application.components.flash.Flash',

	),


	'components'=>array(

		'loader' => array(

			'class' => 'application.components.shared.Loader'

		),

		'mail' => array(

			'class' => 'application.extensions.mail.Mail',

			'debug'=>false,

		),

		'urlManager'=>array(

			'urlFormat'=>'path',

			'showScriptName'=>false,

			'rules'=>array(

				'category/<id>'=>'category/list',

			),

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning, info, watch',

					'categories'=>'system.*',

				),

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'info',

					'categories'=>'image.thumbGeneration',

					'logFile'=>'image.log'

				),

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'info',

					'categories'=>'image.noThumbGeneration',

					'logFile'=>'imageX.log'

				),

			),

		),

		'user'=>array(

			'class'=>'WebUser',

			'allowAutoLogin'=>true,

		),

		'db'=>array(

			'enableParamLogging'=>true,

			'schemaCachingDuration'=>YII_DEBUG ? 0 : 3600,

		),

	),


	'params'=>array(

		'adminEmail'=>'a@a.com',

		'infolinks'=>array(

			'About us'=>array('site/about'),

			'Contact us'=>array('site/contact'),

			'Privacy Policy'=>array('site/policy'),

			'Terms & Conditions'=>array('site/terms'),

		),

	),

);



jonah "Advanced Member",

You are not a beginner, In fact your picture says “Advanced Member”, that’s not me…

From a beginner’s perspective, I don’t care if there are three times more lines, until I learn my way around, my method will work fine for me.

It was not my intent to offend anyone, merely to show an alternate way that helped me understand, what’s what and where does it go…

I will save you message and when I get more advanced, I will give it a shot…

Best regards,

Bill Hernandez

Plano, Texas

I don’t think you offended anyone… And I like how you documented all options in the configuration (It’s a nice reference). Also it’s a good thing for people to realize that you can configure it the way you did and that it’s flexible like that

Jonah,

Thanks for taking the time to reply…

I made some changes that accommodate your thoughts, (i.e) I did have an excessive number of lines separating the categories, so I created a second main.php that removed most of the extra divider lines (they were excessive) and also removed a lot of the comments, but did leave the variables that control whether certain items are loaded or not, instead of using the comment/un-comment technique.

If you might have another look and let me know what I can improve, I would be grateful…

http://www.journey-of-flight.com/bh_zend/Yii_FrameWork/easy_config/index.php

Thanks Again,

Bill Hernandez

Plano, Texas

I had posted some information that displayed the highlighted some sample code, and for some reason the highlight routine had slipped by in the cracks during some re-organization. Anyway the sample code is fixed now…

http://www.journey-of-flight.com/bh_zend/Yii_FrameWork/easy_config/index.php

I had tried to get rid of the index.php, so I could have something like :


http://www.journey-of-flight.com/home_brew/software/programming/yii 

instead of :


http://www.journey-of-flight.com/home_brew/index.php/software/programming/yii 

RewriteEngine on

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ ./$1 [L,QSA]

RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

I changed :




        // This adds the index.php to the end of the url, before the Class/Action

        $aArray['components']['urlManager']['showScriptName'] = true;



to :




        // This removes the index.php to the end of the url, before the Class/Action

        $aArray['components']['urlManager']['showScriptName'] = false;



I looked at the two links below, but still could not remove index.php and have things work correctly.

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

http://www.yiiframework.com/forum/index.php?/topic/7803-how-to-remove-index-php-from-url/

Wondering what I might be missing in :


http://www.journey-of-flight.com/bh_zend/Yii_FrameWork/easy_config/index_with_comments.php

http://www.journey-of-flight.com/bh_zend/Yii_FrameWork/easy_config/index_with_comments.php

Any Ideas ?

do you have apache’s rewrite module enabled?

Yes