The topic of one of GORGES recent internal Friday Tech Talks was “Yii CRUD: Tips and Tricks.” I proposed this because I was curious to hear war stories from other developers about the problems and solutions they ran into when building “CRUD” – principally in the Yii framework, which has become one of our favorite tools at GORGES for creating complex web applications.
CRUD stands for Create, Read, Update and Delete (or, for some folks, Create, Retrieve, Update and Destroy). It refers to the basic operations that any data-centered application needs to make it run – creating new objects or records, viewing them, editing them, and getting rid of them. The code that performs these operations tends to get pretty repetitive after a while, so for a seasoned developer it can become the part of the application that you most want to “get out of the way” so you can focus on the more interesting bits, like complex business logic and nifty Javascript widgets. It is also often predominant in the administrative side of an application, where there is typically less budget for fancy design and interactivity than on the public side – but it still needs to work effectively. Thus, when developers refer to it as “crud”, they don’t always have the acronym in mind.
Here are some of the comments I heard from our team on how to create CRUD efficiently, in order to deliver quality, maintainable, cost-effective applications to our clients:
1. Don’t build it at all, if you can help it - For simpler web applications, or ones that are more content-oriented, a “full stack” framework like Yii or Ruby on Rails can be overkill – a platform such as Drupal can take care of most of the housekeeping operations, with coding (or configuration) only required for the more “custom” features of the application.
2. Use code generators – Yii and most other advanced web frameworks include tools for generating “skeleton” code for CRUD operations. Most developers felt that these are a good starting point, especially when first learning a framework, but after a while it becomes more efficient to write from scratch, with judicious use of copy and paste from existing similar code (but beware the Rule of Three).
3. Modularize your MVC components – Even though the Model-View-Controller idiom forces the developer to think in modular terms to some extent, it is still possible to write overly repetitive code within that idiom, and violate the DRY principle. Frameworks such as Yii provide a great foundation for building a web app, but the larger and more complex an application is, the more it makes sense to build on that foundation by using inheritance, polymorphism, and other object-oriented techniques in the CRUD (as well as in the non-CRUD components).
4. Build widgets where appropriate – This is just a specific example of modularization; Yii provides a widget API for building components that can be reused in different areas of an application. There are many standard widgets available, for components such as date pickers, but again, in some cases custom-building just the widget you need for a given application makes sense to keep everything “DRY”.
5. Use advanced languages - Just like application frameworks, many of the standard web development languages provide a great basis, but leave plenty of room for additional optimization. Two tools that our team is very excited about are HAML and SASS, which provide more efficient and elegant syntax for generating XHTML and CSS, respectively, than coding directly to each language. I won’t go into technical details here, but both tools allow the developer to create more robust solutions with fewer keystrokes.
These techniques and the fact that GORGES has structured ways of building staff efficiency, illustrate how GORGES developers are constantly looking for better ways to deliver quality web applications – avoiding CRUD!

