Archives For excerpt

The first thing you’ll need to know to use JavaScript and jQuery in Yii is how to add JavaScript to a Web page. As with any standard Web page, there are two primary options:

Link to an external file that contains the JavaScript code
Place the JavaScript code directly in the page using SCRIPT tags
Just as I assume you’re already comfortable with JavaScript, I’ll also assume you know the arguments for and against both approaches. (Technically, there’s a third option: place the JavaScript inline within an HTML tag. This is not a recommended approach in modern Web sites, however, and I won’t demonstrate it here.)

Continue Reading...

HTML forms are one of the key pieces of any website. As is the case with many things, creating forms while using a framework such as Yii is significantly different than creating forms using standard HTML alone. In Chapter 9, “Working with Forms,” of “The Yii Book“, you’ll learn what you need to know to create HTML forms when using the Yii framework. You’ll comprehend the fundamentals of forms in Yii and see a few recipes for common form needs.

Continue Reading...

Whenever you begin working with a database, you introduce more possible causes of errors. Thus, you must learn additional debugging strategies. When using PHP to run queries on the database, the problems you might encounter include:

An inability to connect to the database
A database error thrown because of a query
The query not returning the results or having the effect that you expect
None of the above, and yet, the output is still incorrect
On a non-framework site, you just need to watch for database errors to catch the first two types of problems. There’s a simple and standard approach for debugging the last two types:

Use PHP to print out the query being run.
Run the same query using another interface to confirm the results.
Debug the query until you get the results you want.
When using a framework, these same debugging techniques are a little less obvious, in part because you may not be directly touching the underlying SQL commands. Thankfully, Yii will still be quite helpful, if you know what switches to flip.

Continue Reading...

The CDbCriteria class let’s you customize queries through an object. The first thing you should do to become more comfortable with Active Record when using the Yii framework is master usage of CDbCriteria.

This is an excerpt from Chapter 8, “Working with Databases,” of “The Yii Book”.

Continue Reading...

Let’s look at a different way of rendering view files: using static pages. The difference between a static page and a standard page in the site is that the static page does not change based upon any input. In other words, a dynamic page might display information based upon a provided model instance, but a static page just displays some hard-coded HTML (in theory).

This is an excerpt from Chapter 7, “Working with Controllers,” of “The Yii Book”.

Continue Reading...