A long, long time ago, in a land far, far away (as far as I know), Jonah Turnquist wrote an article on validation scenarios in Yii. It’s a topic that I hadn’t paid too much attention to until playing around with the “search” scenario added in more recent versions of Yii (1.1 or thereabouts). If you’re curious about what validation scenarios are, Jonah’s post is a great little introduction.
Archives For yii
I’ve spent the past couple of weeks developing a search engine for a Yii-based site (my problems and solutions specific to the search engine will be addressed in a separate post). As you may know, a search engine is really two things:
- One tool for creating the site index
- Another tool for searching the index and displaying the results
For both, I used the Zend_Search_Lucene module within Yii (or, I think that’s the route I’ll end up using). And although I initially created a Controller method for generating the index (per the instructions I sketched out in this other post), indexing a lot of content through a Web request is less than ideal. This particular site probably only has a hundred or more database records and a couple dozen files (PDFs) to be indexed, but the process still took a minute or two. Even if the index is only created or updated once a day or once a week, that’s still a lot of Web server resources being tied up. A better solution is to use a command-line script to create the index. Since most of the indexing requires a database connection and some Model information, I didn’t want to separate the indexing script from the Yii-based site. Fortunately, Yii supports command-line scripts by creating a “console application”. As with other things in Yii that are less common, the documentation on console applications is meager, but it was enough for me to go on. Here’s what you need to know… Continue Reading…
Over the past two days I updated all eight posts in my “Learning the Yii Framework” series. The series was originally begun in June of 2009, starting with version 1.0.6 of Yii. A fair amount has changed since then, particularly the switch from using the command-line tool to using the Web-based Gii to generate code. So I reviewed all of the writing and code to make sure it was up-to-date with what users will see when developing with Yii today (current version: 1.1.4). The introduction of Gii was the largest change, although a while back Yii also switched from a “list” Controller method with a “list” View file to “index” and “index”; also “show” became “view”. And the Zii extension of widgets are now used extensively (um…pun).
Considering the popularity of this series, I’m not thinking of self-publishing a complete Yii guide (depending upon how I feel after self-publishing a JavaScript book).
Normally two Models in an MVC architecture are related to each other, such as Employees and Departments (to use the classic example), where each employee is in one department and each department has multiple employees. Although Yii does a great job of auto-generating most of the code you need, including the form used to create and update a Model, the Yii-generated form won’t properly represent the related Model. In this post I’ll walk you through what you need to do to make your forms work properly for related Models. Continue Reading…
On a recent Yii-based project, managing one of the Models required a whole slew of checkboxes to indicate that yes, the quality does apply, or no, it does not. In this case, the value being stored in the database for each attribute was a single letter: Y/N. However Yii, when showing the form to update an item, needs the checkbox value to be a Boolean, in order to properly pre-check the box. Changing the database wasn’t an option in this case, so I had to figure out a good conversion process. In this post, I’ll tell you exactly how I solved this issue. Continue Reading…