Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Agile Web Application Development with Yii1.1 and PHP5

You're reading from   Agile Web Application Development with Yii1.1 and PHP5 For PHP developers who know object-oriented programming, this book is the fast track to learning the Yii framework. It takes a step-by-step approach to building a complete real-world application ‚Äì teaching by practice rather than theory.

Arrow left icon
Product type Paperback
Published in Aug 2010
Publisher Packt
ISBN-13 9781847199584
Length 368 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (19) Chapters Close

Agile Web Application Development with Yii 1.1 and PHP5
Credits
About the Author
About the Reviewers
Preface
1. Meet Yii FREE CHAPTER 2. Getting Started 3. The TrackStar Application 4. Iteration 1: Creating the Initial TrackStar Application 5. Iteration 2: Project CRUD 6. Iteration 3: Adding Tasks 7. Iteration 4: User Management and Authentication 8. Iteration 5: User Access Control 9. Iteration 6: Adding User Comments 10. Iteration 7: Adding an RSS Web Feed 11. Iteration 8: Making it Pretty - Design, Layout, Themes, and Internationalization(i18n) 12. Iteration 9: Modules - Adding Administration 13. Iteration 10: Production Readiness Index

MVC architecture


As mentioned previously, Yii is an MVC framework and it provides an explicit folder structure for each piece of model, view, and controller code. Before we start building our first Yii application, we need to define a few key terms, and look at how Yii implements and enforces this MVC architecture.

The model

Typically in an MVC architecture, the model is responsible for maintaining state. Thus, it should encapsulate the business rules that apply to the data that defines this state. A model in Yii is any instance of the framework class CModel or its child class. A model class typically comprises data attributes that can have separate labels (something user-friendly for the purpose of display), and can be validated against a set of rules defined in the model. The data that makes up the attributes in the model class could come from a row of a database table or from the fields in a user input form.

Yii implements two kinds of models: The form model (CFormModel class) and the active record model (CActiveRecord class). They both extend from the same base class CModel. CFormModel represents a data model that collects inputs in HTML form. It encapsulates all the logic for form field validation and any other business logic that may need to be applied to the form field data. It can then store this data in memory, or with the help of an active record model, store data in a database.

Active Record (AR) is a design pattern used to abstract database access in an object-oriented fashion. Each AR object in Yii is an instance of CActiveRecord or its child class that wraps a single row in a database table or view, encapsulates all the logic and details around database access, and houses much of the business logic that is required to be applied to that data. The data field values for each column in the table row are represented as properties of the AR object. AR is described in more detail a little later.

The view

Typically, the view is responsible for rendering the user interface, based on the data in the model. A view in Yii is a PHP script that contains user interface related elements, often built using HTML, but can also contain PHP statements. Usually any PHP statements within the view are very simple conditional or looping statements, or refer to other Yii UI-related elements such as HTML helper class methods or prebuilt widgets. More sophisticated logic should be separated from the view and placed appropriately in either the model (if dealing directly with the data), or in the controller for a more general business logic.

The controller

The controller is our main director of a routed request and is responsible for taking user input, interacting with the model, and instructing the view to update and display appropriately. A controller in Yii is an instance of CController or its child. When a controller runs, it performs the requested action, which then interacts with needed models and renders an appropriate view. An action, in its simplest form, is a controller class method whose name starts with the word action.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Agile Web Application Development with Yii1.1 and PHP5
You have been reading a chapter from
Agile Web Application Development with Yii1.1 and PHP5
Published in: Aug 2010
Publisher: Packt
ISBN-13: 9781847199584
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime
Modal Close icon
Modal Close icon