Archives For mvc

HTML forms are one of the key pieces of any website. As is the case with many things, creating forms while using a framework such as Yii is significantly different than creating forms using standard HTML alone. In Chapter 9, “Working with Forms,” of “The Yii Book“, you’ll learn what you need to know to create HTML forms when using the Yii framework. You’ll comprehend the fundamentals of forms in Yii and see a few recipes for common form needs.

Continue Reading...

Let’s look at a different way of rendering view files: using static pages. The difference between a static page and a standard page in the site is that the static page does not change based upon any input. In other words, a dynamic page might display information based upon a provided model instance, but a static page just displays some hard-coded HTML (in theory).

This is an excerpt from Chapter 7, “Working with Controllers,” of “The Yii Book”.

Continue Reading...

Content decorators are a less heralded but interesting feature of the Yii framework. Content decorators allow you to hijack the view rendering process and add some additional stuff around the view file being rendered. In this excerpt from Chapter 7, “Working with Controllers,” of “The Yii Book”, I’ll explain what content decorators are and how you use them. (This does assume you have some familiarity with Yii and how it renders the complete layout.)

Continue Reading...

Much of the work done with models involves using the methods defined within the model classes. These methods, such as rules() and relations(), are created by the code generator Gii. You’ll also add your own methods to the code generated for you. But, thanks to inheritance, there are lots of methods common to Yii models that you’ll frequently use. In this post, I want to specifically look at methods used to handle model-related events. Before looking at the usage of these methods, let’s first look at event handling in Yii in general.

Continue Reading...

Using the Model-View-Controller (MVC) design pattern, the look of a Yii-based site is naturally controlled by the View files. These files are a combination of HTML and PHP that help to create the desired output. Specific pages in a site will use specific View files. In fact, the View files are designed to be broken down quite atomically, such that, for example, the form used to both create and edit an employee record is its own file, and that file can be included by both create.php and update.php. As with most things in OOP, implementing atomic, decoupled functionality goes a long way towards improving reusability. But the individual View files are only part of the equation for rendering a Web page. Individual view files get rendered within a layout file. And although I’ve mentioned layouts a time or two in my writings on Yii, it’s a subject that deserves its own post. Continue Reading…