Follow the instruction as suggested in this video tutorial to develop a simple web application using Yii Framework and see the power of Yii Framework.
To create a new application, we are going to use a little powerhouse of a tool that comes packaged with the framework, called yiic. This is a command-line tool that you can use to quickly bootstrap a brand new Yii application. It is not mandatory to use this tool, but it saves time and guarantees that a proper directory and file structure is in place for the application.To use this tool, open up your command line, and navigate to a place in your filesystem where you will want to create your application’s directory structure. For the purpose of this demo application, we will assume the following:
• YiiRoot is the name of the directory where you have installed the Yii framework files
• WebRoot is configured as a document root of your web server From your command line, change to your WebRoot directory and execute the
% cd WebRoot
% YiiRoot/framework/yiic webapp helloworld
Create a Web application under ‘/Webroot/helloworld’? [Yes|No]
Your application has been created successfully under /Webroot/helloworld.
The yiic command may not work for you as expected, especially if you are attempting to use it in a Windows environment. The yiic file is an executable that runs using your command-line version of PHP. It invokes
the yiic.php script. You may need to fully qualify by using php in front, as in $ php yiic or $ php yiic.php. You may also need to specify the PHP executable to be used, such as C:\PHP5\php.exe yiic.
php . There is also the yiic.bat file, which executes the yiic.php file, that may be more suitable for Windows users. You may need to ensure that your PHP executable location is accessible in your %PATH% variable.
Please try these variations to find a suitable solution for your computer configuration. I will continue to simply refer to this command as yiic.
The yiic webapp command is used to create a brand new Yii web application. It takes just a single argument to specify either the absolute or relative path to the directory in which the application should be created. The result is the generation of all the necessary directories and files that are used to provide a skeleton of the
default Yii web application. Let’s list the contents of our new application to see what was created for us:
The following is a description of these high-level items that were automatically created:
• index.php: Web application entry script file
• index-test.php: Entry script file for loading a test configuration
• assets/: Contains published resource files
• css/: Contains CSS files
• images/: Contains image files
• themes/: Contains application themes
• protected/: Contains protected (non-public) application files
With the execution of one simple command from the command line, we have created all the directory structure and files needed to immediately take advantage of Yii’s sensible default configuration. All of these directories and files, along with the subdirectories and files that they contain, can look a little daunting at first glance. However, we can ignore most of them as we are getting started. What is important to note is that all of these directories and files are actually a working web application. The yiic command has populated the application with enough code to establish a simple home page, a typical contact-us page to provide an example of a web form, and a login page to demonstrate basic authorization and authentication in Yii. If your web server supports the GD2 graphics library extension, you will also see a CAPTCHA widget on the contact-us form, and the application will have the corresponding validation for this form field.
As long as your web server is running, you should be able to open up your browser and navigate to http://localhost/helloworld/index.php. Here you will be presented with a My Web Application home page along with the friendly greeting Welcome To My Web Application, followed by some helpful next steps
You will need to ensure that both the assets/ and protected/runtime/ directories are writable by your web server process, otherwise you may see an error rather than the working application.You’ll notice that there is a working application navigation bar along the top of the page. From left to right there is Home, About , Contact, and Login . Click around and explore. Clicking on the About link provides a simple example of a static page. The Contact link will take you to the contact us form that was mentioned before, along
with the CAPTCHA input field in the form. (Again, you will only see the CAPTCHA field if you have the gd graphics extension as part of your PHP configuration.) The Login link will take you to a page displaying a login form. This is working code with form validations, as well as username and password credential validation and authentication. Using either demo/demo or admin/admin as the username/password combination will get you logged onto the site. Try it out! You can try a login that will fail (any combination other than demo/demo or admin/admin) and see the error validation messages get displayed. After successfully logging in, the Login link in the header changes to a Logout link (username), where the username is either demo or admin depending on the username that you used to log in. It is amazing that so much has been accomplished without having to do any coding.
With this blog article watch this video tutorial for easy understanding of whole Yii Framework installation process
Prior to installing Yii, you must configure your application development environment as a web server capable of supporting PHP 5.1.0 or above. Yii has been thoroughly tested with the Apache HTTP server on Windows and Linux operating systems. It may also run on other web servers and platforms that support PHP 5. We assume that the reader has previously engaged in PHP development, and has access to or otherwise has knowledge of how to set up such an environment. We will leave the installation of a web server and PHP itself, as an exercise to the reader.
Some popular installation packages include:
• http://www.mamp.info/en/index.html (mac only)
The basic Yii installation is almost trivial. There are really only two necessary steps:
1. Download the Yii framework from
2. Unpack the downloaded file to a web-accessible directory. There are several
versions of Yii to choose from when downloading the framework. We will be using version 1.1.12 for the purpose of this book, which is the latest stable version as of the time of writing. Though most of the example code should work with any 1.1.x version of Yii, there may be some subtle differences if you are using a different version. Please attempt to use 1.1.12 if you are following along with the examples. After you have downloaded the framework files and unpacked them in a web-accessible directory, list the contents. You should see the following high-level
directories and files:
Now that we have our framework unpacked in a web-accessible directory, it is advised that you verify that your server satisfies all of the requirements of using Yii, to ensure that the installation was a success. Luckily, doing so is very easy. Yii comes with a simple requirements checking tool. To use the tool and have it verify
the requirements for your installation, simply point your browser to the index.php entry script under the requirements/ directory that came with the downloaded files. For example, assuming that the name of the directory containing all of the framework files is simply called yii , the URL to access the requirements checker might look like:
Using the requirements checker is not, in itself, a requirement for installation. But it is certainly recommended to ensure proper installation. As you can see, not all of our results under the details section received a Passed status, as some display a Warning result. Of course, your configuration will most likely be slightly different from ours, and consequently your results may be slightly different as well. That is okay. It is not necessary that all of the checks under the Details section pass, but it is necessary to receive the following message under the Conclusion section: Your server configuration satisfies the minimum requirements by Yii .
There is lots of such frameworks are available in market in this programming era. Then you must have a question that whay yii framework? There are lots of reasons why to choose Yii Framework. Let’s explain some of theme one by one.
To run a Yii version 1.x-powered web application, all you need are the core framework files and a web server supporting PHP 5.1.0 or higher. To develop with Yii, you only need to know PHP and object-oriented programming. You are not required to learn any new configuration or templating language. Building a Yii application mainly involves writing and maintaining your own custom PHP classes, some of which will extend from the core, Yii framework component classes.Yii incorporates many of the great ideas and work from other well-known web
programming frameworks and applications. So if you are coming to Yii from using other web development frameworks, it is likely that you will find it familiar and easy to navigate. Yii also embraces a convention over configuration philosophy, which contributes to its ease of use. This means that Yii has sensible defaults for almost all the aspects that are used for configuring your application. Following the prescribed conventions, you can write less code and spend less time developing your application. However, Yii does not force your hand. It allows you to customize all of its defaults and makes it easy to override all of these conventions. We will be covering some of these defaults and conventions later in this chapter and throughout the book.
Yii is a high-performance, component-based framework that can be used for developing web applications on any scale. It encourages maximum code reuse in web programming and can significantly accelerate the development process. As mentioned previously, if you stick with Yii’s built-in conventions, you can get your
application up and running with little or no manual configuration. Yii is also designed to help you with DRY development. DRY stands for Don’t Repeat Yourself, a key concept of agile application development. All Yii applications are built using the Model-View-Controller ( MVC) architecture. Yii enforces
this development pattern by providing a place to keep each piece of your MVC code. This minimizes duplication and helps promote code reuse and ease of maintainability. The less code you need to write, the less time it takes to get your application to market. The easier it is to maintain your application, the longer it will
stay on the market.Of course, the framework is not just efficient to use, it is remarkably fast and
performance optimized. Yii has been developed with performance optimization in mind from the very beginning, and the result is one of the most efficient PHP frameworks around. So any additional overhead that Yii adds to applications written on top of it is extremely negligible.
Yii has been carefully designed to allow nearly every piece of its code to be extended and customized to meet any project requirement. In fact, it is difficult not to take advantage of Yii’s ease of extensibility, since a primary activity when developing a Yii application is extending the core framework classes. And if you want to turn your extended code into useful tools for other developers, Yii provides easy-to-follow steps and guidelines to help you create such third-party extensions. This allows you to contribute to Yii’s ever-growing list of features and actively participate in extending Yii itself
Web development frameworks help jump-start your application by immediately delivering the core foundation and plumbing needed to quickly turn your ideas scribbled on the whiteboard into functional, production-ready code. With all of the common features expected from web applications today, and available framework
options that meet these expectations, there is little reason to code your next web application from scratch. A modern, flexible, and extensible framework is almost as essential a tool to today’s web developer as the programming language itself. And when the two are particularly complementary, the results are an extremely powerful toolkit—Java and Spring, Ruby and Rails, C# and .NET, and PHP and Yii.
Yii is the brainchild of founder Qiang Xue, who started the development of this open source framework on January 1, 2008. Qiang had previously developed and maintained the PRADO framework for many years prior to starting this. The years of experience and user feedback cultivated from the PRADO project solidified the need for a much easier, more extensible, and more efficient PHP5-based framework, to meet the ever-growing needs of application developers. The initial alpha version of Yii was officially released to meet these needs in October of 2008. Its extremely impressive performance metrics when compared to other PHP-based frameworks immediately drew very positive attention. On December 3, 2008, Yii 1.0 was officially released, and as of Oct 1, 2012, the latest production-ready version is up to 1.1.12.
It has a growing development team and continues to gain in popularity among PHP developers everyday. The name Yii is an acronym for Yes, it is , and is pronounced as Yee or ( ji: ). Yii is a high-performance, component-based, web application framework written in PHP5. The name is also representative of the adjectives most used to describe it, such as easy, efficient, and extensible.