Day 4
Theming and extensions
- Applying the theme
- Custom themes
- Extensions
Error handling and testing
‘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.
Download the extension
Unpack the extension
Import, configure and use the extension
Based on PHP 5 exception mechanism.
Error
Exception
- Raising Exceptions
- Displaying Errors
- Handling Errors Using an Action
Raising Exceptions
throw new ExceptionClass('ExceptionMessage');
CException
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);
}
Yii testing Framework is built on top of PHPUnit.
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"