Welcome

to

Yii Training

Prepared by

Shamsher Ansari

Day 4

  1. Theming and extensions
    • Applying the theme
    • Custom themes
    • Extensions
  2. Error handling and testing
    • Error handling
    • Testing

Theme

‘Because some things are better in color’

  • Customizes the outlook of pages.
  • Changes the overall appearance of a Web application

Yii theme is a Directory of

  • View
  • Layout
  • Resources like CSS,JS,LESS

Different Ways to Theming

  • Customize existing Theme
  • Create your own Theme

Lets Download and Apply some theme.

Extensions

  1. Download the extension
  2. Unpack the extension
  3. Import, configure and use the extension

Error Handling

Based on PHP 5 exception mechanism.

Error

Exception

  • Raising Exceptions
  • Displaying Errors
  • Handling Errors Using an Action

Raising Exceptions

						
							throw new ExceptionClass('ExceptionMessage');
						
					
  1. CException
    • generic exception class.
  2. CDbException
    • Caused by some DB-related operations.
  3. CHttpException
    • Caused by HTTP request
    • Returns HTTP Status Code
    • eg: 404 error (page not found)

Displaying Errors

  • WebRoot/themes/ThemeName/views/system
  • WebRoot/protected/views/system
  • yii/framework/views

Handling Errors Using an Action

First Method

						
							return array(
							    ......
							    'components'=>array(
							        'errorHandler'=>array(
							            'errorAction'=>'site/error',
							        ),
							    ),
							);
						
					

Second Method

						
							public function actionError()
							{
							    if($error=Yii::app()->errorHandler->error)
							        $this->render('error', $error);
							}
						
					

Unit Testing

Yii testing Framework is built on top of PHPUnit.

  • CTestCase
  • CDbTestCase
						
						class CommentTest extends CDbTestCase
						{
						    public $fixtures=array(
						        'posts'=>'Post',
						        'comments'=>'Comment',
						    );
						 
						    ......
						}
						
					

Stored under directory protected/tests/unit

Lets do some practical experiment

Questions ?

Ask Google

"No one knows better then Google"

THANK YOU

Shamsher Ansari