Yii Framework Basics
The Yii PHP5 framework makes it possible to rapidly develop web applications under the relatively new three-cause BSD license that allows the framework to be used for either open source or proprietary projects.
The Yii Framework was first released in December of 2008. It is built to (a) be very high performance, (b) use model, view, controller application architecture, and (c) promote clean, DRY (do not repeat yourself) code.
The framework’s creator, Qiang Xue, based much of Yii on his earlier PHP framework, Prado. In fact, Yii builds on everything Xue learned in Prado and was an effort to make a better, higher performance framework option for PHP developers. Yii also employs the convention-over-configuration paradigm made popular with Ruby on Rails, and is integrated with jQuery for Ajax and other client-side interaction.
Download and Unpack the Yii Framework
To get started with Yii, download the most recent stable version from the Yii website.
Unpack the associated archive file in the directory you want Yii to live. Not all of Yii’s files need to be in a web-accessible directory, so you have some flexibility.
The Yii download should contain three directories, demos, framework, and requirements as well as a few text documents including a copy of the license. The various framework components are located — not surprisingly — in the framework directory.
Check that Yii Requirements are Met
The requirements directory is home to an application that will compare a web server’s configuration to Yii’s basic requirements and dependencies. To run this requirements checker, simply point to the requirements directory from a web browser.
As an example, if Yii is installed on a local Apache2 web server in a directory called “yii” the path to the requirements checker would be http://127.0.0.1/yii/requirements.
Strictly speaking, while the first five items in the requirement checker are absolutely requires for Yii to run, these items can be identified in the “Required By” column, since the are necessary for the Yii framework itself.
Create a Basic Web Application
Like Ruby on Rails, Yii can use convention to rapidly bring up a working skeleton application.
To create a Yii skeleton application, navigate to the directory wherein the new application will reside using the server’s shell interface (the command line).
In the command line, execute the yiic command. The path to this command will be the path to the Yii Framework’s framework directory.
The yiic command will take the method webapp and the name of the new application. In the example, the new application is called “ecd.”
It may be necessary to preface this command with “php” depending on your environment.
Yii will ask you if you are certain that you want to create the new application. An answer in the affirmative creates the new application. This application will be instantly available in a web browser.
This application will include a few pages and two forms. The first form is for contacts. The second is for authentication.
This very basically application will, of course, need to be customized, but it is pretty neat to have something up and running so quickly.
The application’s structure is built for MVC, and includes many of the files and classes a developer would want.
The Yii community has a significant amount of support. For example, Jeffrey Winesett, who is part of the current Yii development team, has posted several screencasts to help developers learn Yii.
Winesett has also written a book, Agile Web Application Development with Yii 1.1 and PHP5, that will help beginners become familiar with the framework.
Another book, Yii 1.1 Application Development Cookbook, from Yii development team member Alexander Makarov, is also a good resource for learning the framework.
Finally, the Yii Framework site also has good documentation for getting started.