SlideShare a Scribd company logo
Y I I 
IN ACTION 
KEANY CHU 
http://keanychu.com
KeaNy Chu 
fb.com/keanyc 
@keany_chu
let’s talk about... 
● Module 
● Component 
● Extension
<?php echo “Module” ?>
Module 
Modules are useful in several scenarios. For a large-scale 
application, we may divide it into several modules, each being 
developed and maintained separately. Some commonly used 
features, such as user management, comment management, may be 
developed in terms of modules so that they can be reused easily 
in future projects.
Module 
A module is a self-contained software unit that consists of 
models, views, controllers and other supporting components. In 
many aspects, a module resembles to an application. The main 
difference is that a module cannot be deployed alone and it must 
reside inside of an application. Users can access the 
controllers in a module like they do with normal application 
controllers.
File Structure 
forum/ 
ForumModule.php the module class file 
components/ containing reusable user components 
views/ containing view files for widgets 
controllers/ containing controller class files 
DefaultController.php the default controller class file 
extensions/ containing third-party extensions 
models/ containing model class files 
views/ containing controller view and layout files 
layouts/ containing layout view files 
default/ containing view files for DefaultController 
index.php the index view file
File Structure 
forum/ 
ForumModule.php the module class file 
components/ containing reusable user components 
views/ containing view files for widgets 
controllers/ containing controller class files 
DefaultController.php the default controller class file 
extensions/ containing third-party extensions 
models/ containing model class files 
views/ containing controller view and layout files 
layouts/ containing layout view files 
default/ containing view files for DefaultController 
index.php the index view file
File Structure 
forum/ 
ForumModule.php the module class file 
components/ containing reusable user components 
views/ containing view files for widgets 
controllers/ containing controller class files 
DefaultController.php the default controller class file 
extensions/ containing third-party extensions 
models/ containing model class files 
views/ containing controller view and layout files 
layouts/ containing layout view files 
default/ containing view files for DefaultController 
index.php the index view file
Generator in Gii 
“use the module generator in Gii to create the basic 
skeleton of a new module.”
Config 
// config/main.php 
return array( 
...... 
'modules'=>array('forum',...), 
......);
Config 
// config/main.php 
return array( 
...... 
'modules'=>array( 
'forum'=>array( 
'postPerPage'=>20, 
), 
), 
......);
Usage 
postPerPage=Yii::app()->controller->module->postPerPage;// or the following if 
$this refers to the controller instance// $postPerPage=$this->module- 
>postPerPage;
<?php echo “Component” ?>
Component 
Yii applications are built upon components which are objects 
written to a specification. A component is an instance of 
CComponent or its derived class. Using a component mainly 
involves accessing its properties and raising/handling its 
events. The base class CComponent specifies how to define 
properties and events.
Code 
class Document extends CComponent{ 
public $textWidth;}
Code 
class Document extends CComponent{ 
private $_textWidth; 
public function getTextWidth() 
{ 
return $this->_textWidth; 
}}
Usage 
$document=new Document(); 
// we can write and read textWidth$document->textWidth=100;echo $document- 
>textWidth; 
// we can only read textHeightecho $document->textHeight; 
// we can only write completed$document->completed=true;
Application Component 
To use an application component, we first need to change the application configuration by adding a 
new entry to its components property, like the following:
Application Component 
return array( 
// 'preload'=>array('xyz',...), 
'components'=>array( 
'xyz'=>array( 
'class'=>'ext.xyz.XyzClass', 
'property1'=>'value1', 
'property2'=>'value2', 
), 
// other component configurations 
),);
<?php echo “Extensions” ?>
Extensions 
Extending Yii is a common activity during development. For example, when you 
write a new controller, you extend Yii by inheriting its CController class; when 
you write a new widget, you are extending CWidget or an existing widget class. If 
the extended code is designed to be reused by third-party developers, we call it 
an extension.
Extensions 
Using an extension usually involves the following three steps: 
1. Download the extension from Yii's extension repository. 
2. Unpack the extension under the extensions/xyz subdirectory of application 
base directory, where xyz is the name of the extension. 
3. Import, configure and use the extension. 
Each extension has a name that uniquely identifies it among all extensions. Given 
an extension named as xyz, we can always use the path alias ext.xyz to locate its 
base directory which contains all files of xyz.
Zii Extensions 
Before we start describing the usage of third-party extensions, we would like to introduce the Zii 
extension library, which is a set of extensions developed by the Yii developer team and included in 
every release. 
When using a Zii extension, one must refer to the corresponding class using a path alias in the form 
ofzii.path.to.ClassName. Here the root alias zii is predefined by Yii. It refers to the root directory 
of the Zii library. For example, to use CGridView, we would use the following code in a view script 
when referring to the extension:
Zii Extensions 
$this->widget('zii.widgets.grid.CGridView', array( 
'dataProvider'=>$dataProvider,));
Widget 
Widgets are mainly used in views. Given a widget class XyzClass belonging to the xyz extension, we 
can use it in a view as follows:
Usage 
// widget that does not need body content 
<?php $this->widget('ext.xyz.XyzClass', array( 
'property1'=>'value1', 
'property2'=>'value2')); ?>
Usage 
// widget that can contain body content 
<?php $this->beginWidget('ext.xyz.XyzClass', array( 
'property1'=>'value1', 
'property2'=>'value2')); ?> 
...body content of the widget... 
<?php $this->endWidget(); ?>
DO NOT 
REINVENT 
THE WHEEL
Q&A
KeaNy Chu 
http://keanychu.com 
keanyc@gmail.com

More Related Content

Similar to Yii in action

Actionview
ActionviewActionview
Actionview
Amal Subhash
 
Advance RCP
Advance RCPAdvance RCP
Advance RCP
Rahul Shukla
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
CodeIgniter Conference
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
Oro Inc.
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
 
Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7 Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7
Dhinakaran Mani
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Aaron Saunders
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
Jamie Hurst
 
My Very First Zf App Part One
My Very First Zf App   Part OneMy Very First Zf App   Part One
My Very First Zf App Part One
isaaczfoster
 
Odoo 15 Composition of Module
Odoo 15 Composition of ModuleOdoo 15 Composition of Module
Odoo 15 Composition of Module
Celine George
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
Vishwash Gaur
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-Translator
Dashamir Hoxha
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docs
quyvn
 
Unit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptxUnit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptx
Malla Reddy University
 
Zend Framework 2
Zend Framework 2Zend Framework 2
Zend Framework 2
Tarun Kumar Singhal
 
Mvc in symfony
Mvc in symfonyMvc in symfony
Mvc in symfony
Sayed Ahmed
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
08ui.pptx
08ui.pptx08ui.pptx
08ui.pptx
KabadaSori
 

Similar to Yii in action (20)

Actionview
ActionviewActionview
Actionview
 
Advance RCP
Advance RCPAdvance RCP
Advance RCP
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7 Introduction And Basics of Modules in Drupal 7
Introduction And Basics of Modules in Drupal 7
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 
My Very First Zf App Part One
My Very First Zf App   Part OneMy Very First Zf App   Part One
My Very First Zf App Part One
 
Odoo 15 Composition of Module
Odoo 15 Composition of ModuleOdoo 15 Composition of Module
Odoo 15 Composition of Module
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
 
Using Drupal Features in B-Translator
Using Drupal Features in B-TranslatorUsing Drupal Features in B-Translator
Using Drupal Features in B-Translator
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docs
 
Unit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptxUnit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptx
 
Zend Framework 2
Zend Framework 2Zend Framework 2
Zend Framework 2
 
Mvc in symfony
Mvc in symfonyMvc in symfony
Mvc in symfony
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
08ui.pptx
08ui.pptx08ui.pptx
08ui.pptx
 

Recently uploaded

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 

Recently uploaded (20)

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 

Yii in action

  • 1. Y I I IN ACTION KEANY CHU http://keanychu.com
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. let’s talk about... ● Module ● Component ● Extension
  • 9. Module Modules are useful in several scenarios. For a large-scale application, we may divide it into several modules, each being developed and maintained separately. Some commonly used features, such as user management, comment management, may be developed in terms of modules so that they can be reused easily in future projects.
  • 10. Module A module is a self-contained software unit that consists of models, views, controllers and other supporting components. In many aspects, a module resembles to an application. The main difference is that a module cannot be deployed alone and it must reside inside of an application. Users can access the controllers in a module like they do with normal application controllers.
  • 11. File Structure forum/ ForumModule.php the module class file components/ containing reusable user components views/ containing view files for widgets controllers/ containing controller class files DefaultController.php the default controller class file extensions/ containing third-party extensions models/ containing model class files views/ containing controller view and layout files layouts/ containing layout view files default/ containing view files for DefaultController index.php the index view file
  • 12. File Structure forum/ ForumModule.php the module class file components/ containing reusable user components views/ containing view files for widgets controllers/ containing controller class files DefaultController.php the default controller class file extensions/ containing third-party extensions models/ containing model class files views/ containing controller view and layout files layouts/ containing layout view files default/ containing view files for DefaultController index.php the index view file
  • 13. File Structure forum/ ForumModule.php the module class file components/ containing reusable user components views/ containing view files for widgets controllers/ containing controller class files DefaultController.php the default controller class file extensions/ containing third-party extensions models/ containing model class files views/ containing controller view and layout files layouts/ containing layout view files default/ containing view files for DefaultController index.php the index view file
  • 14. Generator in Gii “use the module generator in Gii to create the basic skeleton of a new module.”
  • 15. Config // config/main.php return array( ...... 'modules'=>array('forum',...), ......);
  • 16. Config // config/main.php return array( ...... 'modules'=>array( 'forum'=>array( 'postPerPage'=>20, ), ), ......);
  • 17. Usage postPerPage=Yii::app()->controller->module->postPerPage;// or the following if $this refers to the controller instance// $postPerPage=$this->module- >postPerPage;
  • 19. Component Yii applications are built upon components which are objects written to a specification. A component is an instance of CComponent or its derived class. Using a component mainly involves accessing its properties and raising/handling its events. The base class CComponent specifies how to define properties and events.
  • 20. Code class Document extends CComponent{ public $textWidth;}
  • 21. Code class Document extends CComponent{ private $_textWidth; public function getTextWidth() { return $this->_textWidth; }}
  • 22. Usage $document=new Document(); // we can write and read textWidth$document->textWidth=100;echo $document- >textWidth; // we can only read textHeightecho $document->textHeight; // we can only write completed$document->completed=true;
  • 23. Application Component To use an application component, we first need to change the application configuration by adding a new entry to its components property, like the following:
  • 24. Application Component return array( // 'preload'=>array('xyz',...), 'components'=>array( 'xyz'=>array( 'class'=>'ext.xyz.XyzClass', 'property1'=>'value1', 'property2'=>'value2', ), // other component configurations ),);
  • 26. Extensions Extending Yii is a common activity during development. For example, when you write a new controller, you extend Yii by inheriting its CController class; when you write a new widget, you are extending CWidget or an existing widget class. If the extended code is designed to be reused by third-party developers, we call it an extension.
  • 27. Extensions Using an extension usually involves the following three steps: 1. Download the extension from Yii's extension repository. 2. Unpack the extension under the extensions/xyz subdirectory of application base directory, where xyz is the name of the extension. 3. Import, configure and use the extension. Each extension has a name that uniquely identifies it among all extensions. Given an extension named as xyz, we can always use the path alias ext.xyz to locate its base directory which contains all files of xyz.
  • 28. Zii Extensions Before we start describing the usage of third-party extensions, we would like to introduce the Zii extension library, which is a set of extensions developed by the Yii developer team and included in every release. When using a Zii extension, one must refer to the corresponding class using a path alias in the form ofzii.path.to.ClassName. Here the root alias zii is predefined by Yii. It refers to the root directory of the Zii library. For example, to use CGridView, we would use the following code in a view script when referring to the extension:
  • 29. Zii Extensions $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider,));
  • 30. Widget Widgets are mainly used in views. Given a widget class XyzClass belonging to the xyz extension, we can use it in a view as follows:
  • 31. Usage // widget that does not need body content <?php $this->widget('ext.xyz.XyzClass', array( 'property1'=>'value1', 'property2'=>'value2')); ?>
  • 32. Usage // widget that can contain body content <?php $this->beginWidget('ext.xyz.XyzClass', array( 'property1'=>'value1', 'property2'=>'value2')); ?> ...body content of the widget... <?php $this->endWidget(); ?>
  • 33.
  • 34. DO NOT REINVENT THE WHEEL
  • 35. Q&A
  • 36. KeaNy Chu http://keanychu.com keanyc@gmail.com