-
Book Overview & Buying
-
Table Of Contents
Yii Application Development Cookbook - Second Edition - Second Edition
If you have some code that looks like it can be reused, but you don't know if it's a behavior, widget, or something else, most probably it's a component
. A component should be inherited from CComponent or CApplicationComponent. Later on, the component can be attached to the application and configured using the protected/config/main.php configuration file. That's the main benefit compared to using just a plain PHP class. Additionally, we are getting behaviors, events, getters, and setters support.
For our example we'll implement a simple EImageManager application component that will be able to resize images using the GD library, attach it to the application, and use it.
You will need to install the GD PHP extension to see image resizing in action.
Create protected/components/EImageManager.php:
<?php
class EImageManager extends CApplicationComponent
{
protected $image;
protected $width;
protected $height;
protected $newWidth;
protected...
Change the font size
Change margin width
Change background colour