Welcome – Yii Training



Welcome – Yii Training

0 0


yii-training-day-4

Yii Training Day 4

On Github shamsher31 / yii-training-day-4

Welcome

to

Yii Training

Prepared by

Shamsher Ansari

Day 4

Theming and extensions
  • Applying the theme
  • Custom themes
  • Extensions
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

Download the extension Unpack the extension 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');
						
					
CException
  • generic exception class.
CDbException
  • Caused by some DB-related operations.
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