Yii Framework in the RAD context + Mashup demo built on YII
Yii framework in the RAD context George-Leonard Chetreanu Faculty of Computer Science, Iasi, Romania firstname.lastname@example.org Abstract. The following papar provides a general view on RAD topic as well as a short presentation of a particular development tool targeting the web. M otivation for choosing the tool and a comparison with its alternatives are also present. Keywords: Web, database, DAO, AJAX, REST, services1 Overvie w1.1 Definiti onTrying to answer what RAD means, it can be noted that there are various definition sand exp lanations for the term, out of wh ich some worth mentioning are the fo llowing: James Mart in, in his book first coining the term in 1991, wrote, “Rapid Application Develop ment (RAD) is a development lifecycle designed to give much faster development and higher-quality results than those achieved with the traditional lifecycle. It is designed to take the maximu m advantage o f powerful development software that has evolved recently.” Professor Clifford Kettemborough of Whitehead College, University of Redlands, defines Rapid Applicat ion Develop ment as “an approach to building co mputer systems which combines Co mputer-Assisted Software Engineering (CASE) tools and techniques, user-driven prototyping, and stringent project delivery time limits into a potent, tested, reliable formula for top-notch quality and productivity. RAD drastically raises the quality of finished systems while reducing the time it takes to build them.” Online Knowledge defines Rapid Applicat ion Develop ment as “a methodology that enables organizations to develop strategically important systems faster while reducing development costs and maintaining quality. Th is is achieved by using a
YII framework in the RAD context series of proven application development techniques, within a well-defined methodology.” To put it shortly, RAD is a method and a set of tools allowing the rapid productionof software systems from concept to finish1. This technique emphasizes extensive userinvolvement in the rapid and evolutionary construction of working prototypes of asystem to accelerate the system develop ment process. RAD is sometimes referred tothe “spiral approach” (see Fig.1) because the nature of the technique involvesrepeatedly spiraling through the phases to construct a system with various levels ofcompleteness and complexity 2. RAD was a response to non-agile processes developedin the 1970s, such as the “Waterfall” model. The problem with previousmethodologies was that applications took so long to build that requirements hadchanged before the system was comp lete, often resulting in unusable systems. Originally intended to describe a process involving application prototyping anditerative develop ment, the term has become a marketing buzzword that genericallydescribes applications that can be designed and developed within 60-90 days. Fig. 1 RAD Diagram by James P.1 http://wysterdesir.com/2008/09/28/using-rapid-application-development-for-your-software- project/2 http://www.jscgroup.com/rapid-application-development.html
YII framework in the RAD context1.2 Prerequisites3 Gathering requirements using workshops or focus groups Prototyping and early, reiterat ive user testing of designs The re-use of software co mponents A rigid ly paced schedule that defers design imp rovements to the next product version Less formality in reviews and other team co mmunicat ion 4, 51.3 Advantages Speed: the speed increases can be achieved using a variety of methods including, rapid prototyping, virtualization of system related routines, the use of CASE tools and other techniques. Quality: as defined by RAD, quality is both the degree to which a delivered application meets the needs of users as well as the degree to which a delivered system has low maintenance costs. RAD increases quality through the involvement of the user in the analysis and design stages. Some systems also deliver advantages of interoperability, extensibility, and portability.1.4 Disadvantages Reduced scalability: because RAD focuses on development of a prototype that is iteratively developed into a full system, the delivered solution may lack the scalability of a solution that was designed as a full application fro m the start. Reduced feature sets: due to time bo xing, where features are pushed off to later versions in favor of delivering an application in a short time frame, RA D may produce applications that are less full featured than traditionally developed applications. This concern should be addressed as soon as possible through clear communicat ion with the client as to what will be delivered and when.3 http://searchsoftwarequality.techtarget.com/definition/rapid-application-development4 http://www.blueink.biz/RapidApplicationDevelopment.aspx5 http://www.selectbs.com/analysis-and-design/what-is-rapid-application-development
YII framework in the RAD context2 YII Frame work Yii is an open source, object-oriented, high-performance, co mponent-based PHPweb application framework best suited for developing Web 2.0 applications. Writtenin PHP, it pro motes clean, DRY design and encourages rapid development. It worksto streamline your applicat ion development and helps to ensure an extremelyefficient, extensible, and maintainable end product. Its clear mission statement is very much alike with some ideas behind the RADmethodology: Yii helps Web developers build complex applications and deliver themon-time. Being designed with performance in mind, Yii is a great choice for any sizedproject ranging fro m simp le websites to sophisticated, enterprise applications. WithYII the developer has full control over the configuration from head-to-toe(presentation-to-persistence) to conform to any particular enterprise developmentguidelines. The framework co mes packaged with tools to help test and debug theapplications built on it. It worth ment ioning that developers have easy access to aclear and comprehensive documentation along with plenty of other resources toinspire or help things get started. YII development has been inspired by other well-known and proven frameworksand applications like Prado, Ruby on Rails, jQuery, Sy mfony or Joo mla.2.1 Features 6 Model-View-Controller (MVC) design pattern: adopts the proven MVC architecture, wh ich allows for clean separation of concerns (SoC). Database Access Objects (DAO), Query Builder, Active Record, DB Migration : allo ws developers to model database data in terms of objects and avoid the tedium and complexity of writ ing repetitive SQL statements. Form input and validation: allows collecting form input extremely easy and safe. It comes with a set of validators as well as numerous helper methods and widgets to simp lify the task for form input and validation. AJAX-enabled widgets: integrates jQuery and provides a set of AJAX-enabled widgets, such as auto-complete input field, treeview, data grid, which enables writing highly efficient and versatile user interface extremely simp le. Authentication and authorization: built-in support for authentication and also for authorization via h ierarch ical role -based access control (RBA C).6 http://www.Yiiframework.com/features/
YII framework in the RAD context Skinning and theming: the implemented mechanism allows developers to quickly switch the outlook of a Yii-powered website. Web services: supports automatic generation of comp lex WSDL service specifications and management of Web service request handling. Internationalization (I18N) and localization (L10N) : supports message translation, date and time formatting, nu mber formatting, and interface localizat ion. Layered caching scheme: supports data caching, page caching, fragment caching and dynamic content. The storage medium of caching can be changed easily without touching the application code. Error handling and logging: Errors are handled and presented more nicely, and log messages can be categorized, filtered and routed to different destinations. Security: equipped with many security measures to help prevent your Web applications fro m attacks such as SQL in jection, cross -site scripting (XSS), cross- site request forgery (CSRF), and cookie tampering. Unit and functionality testing: support for writ ing and running unit tests as well as functionality tests, based on PHPUn it and Selen iu m. Automatic code generation: provides a set of intuitive and highly extensible code generation tools that can help you quickly generate the code you need for features such as form input, CRUD. Compliance to XHTML: HTM L code produced by Yii co mponents and code generators complies to the XHTM L standard. Purely object-oriented: sticks to strict OOP paradig m. It does not define any global function or variable. And the class hierarchy that it defines allows maximu m reusability and customizat ion. Friendly with third-party code: designed to work well with third-party code, fro m PEAR o r Zend Framework, for examp le. Detailed documentation: Every single method or property is clearly documented and there are also plenty of other resources at hand (tours, book and comprehensive tutorials, wiki, blogs of enthusiastic users sharing code snippets and more). Extension library: base functionality can always be extended by adding user- contributed components that are grouped in an extension lib rary.2.2 Comparison with alternative solutionsGeneralAs opposed to other RAD tools based on technologies other than PHP, YII frameworkdoesn’t have a custom IDE to allow developers to build application in a „visual”fashion by using forms, wizards or „drag-and-drop” editing to get components in
YII framework in the RAD contextplace and connected. However, YII provides a web-based GUI for its code generationand customizat ion functions, which can be seen as a basic but satisfactory alternativeto the capabilit ies of an actual IDE. Since the main focus when developing a businessapplication is to correctly model the requirements/necessities and make prototypes tomirror real-life aspects, the way YII wo rks couldn’t be more appropriate: provided adatabase model was designed, the framework then takes over and takes care of all thefunctionality needed in order to interact with the model, allowing the developer tohandle the implementation of the business logic instead of loosing time „reinventingthe wheel”. Furthermore, certain well-established development tools already provide supportand integration for YII. CodeLobster PHP Edit ion is a very good choice for a fullyfeatured IDE designed for web development that, among other important benefits,helps develop YII based applications. The very nature of YII Framewo rk and its lack of an IDE doesn’t recommend it fornon-technically skilled users, as oppos ed to some RA D tools wh ich, providing a lot ofautomation and heavy visual editing, enable users with little o r no programmingknowledge to produce web applications. However, it worth mentioning that theresulting applications in such cases are either not very complex or they are very hardto customize in ways different to those taken into account by the tool’s developers.Same technol ogy Fig.2 shows how efficient is Yii co mpared with other popular PHP frameworks. Inthe graph, RPS stands for "request per second" which describes how many requests anapplication written in a framework can process per second. The higher the number,the more efficient a framework is. It can be easily seen that Yii outperforms all other frameworks in this comparison.The performance advantage of Yii is especially significant when the widelyused APC extension is enabled.
YII framework in the RAD context Fig. 1. Speed test obtained with ApacheBench tool7Co mparing Yii with one of its main, still more popular and widely us ed competitor,CakePHP, there are quite a few things that make Yii better: PHP 5 features included in the core: First, and most importantly, what allows for most of the stuff that I love in Yii over CakePHP is that it is PHP 5 only. PHP 4 is not supported. Because of this, Yii is able to take use of many PHP 5 features that Cake is not able to (like magic overloading functions ) OOP style AR and lazy loading: Yii takes use of PHP 5’s overloading functions in its AR implementation in a very beautifu l manner. Instead of storing results from queries in an array as Cake does, Yii allo ws accessing the queries in an OOP manner. Excellent Documentation Fast and useful developer feedback : Along with the documentation the Yii foru m is also an excellent place to get help. More easily extended: This can be easily seen for the validation rules: beside permitting to define an action in the model as a validation as in Cake, YII allows to also define a whole class to be a validation type.7 http://www.Yiiframework.com/performance/
3 Mashup demo applicationThe envisioned mashup application was planned to bring together functionality /webservices from Twitter, Flickr and Google Maps. To run the application the user isrequired to provide his Twitter account name (username). This is the only informationneeded to start retrieving relevant data about the user, which will be nicely presentedin a combined fashion on the homepage and on the Map page.The flow of the application is described below:1. The account name is used to obtain the real name of the user and his address, along with other Twitter related information (like his latest tweet and various statistics about his twitting activity).2. The real name is then used to look up photos of the user on Flickr. If the user is not found on Flickr or doesn’t have any public photos available, the application will search for photos from the user’s location. This search is customized to return photos meeting a couple of criteria (like to be taken indoor an d to have geolocation information available).On homepage:1. The user’s name, profile picture and latest tweet (with the date when it was posted) are displayed.2. Twitter tab is populated with Twitter gathered information.3. A limited number of the photos are used to create a photo gallery placed inside the Flickr tab. Each photo is listed along with the date when it was uploaded to Flickr. Clicking on a photo opens the normal sized version along with its title.On Map page:1. The user’s profile picture is plotted on the map to the user’s location. Rolling over with the mouse will display the user’s name. Clicking on it will display the user’s latest tweet.2. For all photos that have geolocation data available (latitude and longitude) a photo icon is placed on the map in the right location. Rolling over an icon with the mouse will display the photo’s title. Clicking the icon will display an info box containing the small size version of the photo and other details beside its title (date added, tags, views). Clicking the actual photo from this box will open the original Flickr photo in a separate browser window/tab.
YII framework in the RAD context3.1 Project setupCoding was done with CodeLobster PHP Edition, which, as previously mentioned,provides support for creating YII applications. XAMPP for Windows (PHP5) wasused to host and run the project locally.Using the “New Project” wizard from CodeLobster (File->New->Project->CreateEmpty Yii Site) a fresh skeleton of a YII application was deployed within minutesinto the htdocs directory of the web server. The newly created application was alreadyfunctional without any intervention made to the code and could be run in a browser,having a default structure which included the following pages: Homepage, About(static), Contact and Login.3.2 CustomizationThe look of the application was edited from the main CSS file (root/css/main.css).Changes in the default actions (what to do on each page) required the update of theapplication’s main controller (root/protected/controllers/SiteController.php).Menu links were edited from the main template file (root/views/layouts/main.php).General settings (application name, enabling friendly URLs and extensions imports –paths instead of params) required the update of the application’s configuration file(root/protected/config/main.php)To add new functionality to the framework, the following extensions were installed(by simply copying their files to root/protected/extensions/ :1. EActiveResource2. httpclient3. jquery-gmap4. phpThumb5. jqPrettyPhoto6. ImageHelperTo make use of the new functionality, the following models were coded (and added toroot/protected/models):1. FlickrUser – in charge of consuming web services from Flickr2. TwitterUser – in charge of consuming web services from TwitterSince the intended mashup didn’t require authenticating the user, the Login page wasmodified (and its title and menu link changed to “Settings”) to serve as the placewhere the user inputs his Twitter account name. The existing form code was editedaccordingly to leave only one field for the user to fill. The changes were performed tothe following files:
YII framework in the RAD context1. root/protected/models/LoginForm.php2. root/protected/views/login.phpHomepage template (root/protected/views/index.php) was edited to display generaluser information and a tabs widget. The widget required two new template files to becoded:1. root/protected/views/tabTwitter.php2. root/protected/views/tabFlick.phpThe “About” page template (root/protected/views/about.php) was edited (andrenamed to map.php) to display the custom Google Map. The “About” page title andits menu link were changed to “Map”.These were all the changes made in order to get the mashup functionality in place. Allother files of the generated Yii application were not modified.