Identified Issues

[size="4"]NOTE: All of the examples provided in the book were completed with Yii version 1.1.2. Many readers are using the latest stable version of Yii (currently 1.1.5) to following along with the examples in the book. There are some subtle API/method signature differences (esp in some of the Gii auto-generated code) between these two versions. If you are using any version other than 1.1.2 to following along, you may have to make some adjustments to the examples used in the book.[/size]

[list=1][*][size="4"]Typo/Printing: Preface, Page 1 -

The first section title reads: "What this book cover" it should read: "What this book covers" or "What is covered in this book"[/size][*][size="4"]Typo/Printing: Preface, Page 3 -

Under the Conventions section, it is describing how code words in the text are shown and it uses the sentence: “You can type in help to see a list of commands available to you within his shell” It should be “…this shell” (i.e. ‘his’ should be ‘this’)[/size][*][size=“4”]Style Formatting: Page 20 -

The sentence:

"Your application has been created successfully under /Webroot/demo/"

should still be in code format style, as it is still part of the output from running the shell command.[/size][*][size="4"]Code Fragment: Page 105 -

The code does not explicitly include the class in which the method should reside. The function is fine, but it could be misleading. The public function


needs to reside in a class. The full code is

class IssueTest extends CDbTestCase 


	public function testGetTypes() 


		$options = Issue::model()->typeOptions; $this->assertTrue(is_array($options)); 



[/size][*][size="4"]Typo/Printing: Page 131 - The following line is missing a closing > bracket to delimit the end of the php statement: [/size]

<b><?php echo CHtml::encode($data->getAttributeLabel('status_id')); ?:</b>

                                                                                                            	[size=&quot;4&quot;]It should be:[/size]

<b><?php echo CHtml::encode($data->getAttributeLabel('status_id')); ?>:</b>

[*][size="4"]Typo/Printing: Page 142 -

The very beginning sentence on this page has several issues. The sentence as it is printed is impossible to understand. The entire sentence should read: [extract]"As these links originate from the issue details page, we can take advantage of the associated project, and alter the links to pass in the specific project id. We can then use that project id as the criteria to limit the Issues returned by the query in both the IssueController::actionIndex(), and IssueController::actionAdmin() methods."[/extract][/size][*][size="4"]Type/Printing: Page 142 -

There is a word 1/2 way down the page that is printed as "conssue", it should be "context": "…implemented a filter to enforce a valid project context"[/size][*][size="4"]Dated Code Snippet: Page 163 -

The auto-generated code displayed for the


method is from a version of the yiic webapp command that is prior to 1.1.2. It should be:

public function authenticate()



			// username => password






		else if($users[$this->username]!==$this->password)




		return !$this->errorCode;


[/size][*][size="4"]Code Typo: Page 190 -

sql query line [sql]primary key (projectId,userId,role)[/sql] should be [sql]primary key (project_id,user_id,role)[/sql][/size][*][size="4"]Code Typo: Page 193 -


is missing the parentheses. It should be


[/size][*][size="4"]Informational Note: Page 198 -

You might need to define the foreign key relationship on tbl_project_user_role.project_id to automatically handle deletes of rows in the project table. Otherwise, you might get a constraint violation error when the unit test ProjectTest::testDelete() is run.

in MySQL, something like [sql]ON DELETE CASCADE ON UPDATE CASCADE[/sql]

NOTE: The book is attempting to stay database independent, and the low level DDL statements for tables are intended to be general (i.e. not MySQL specific). However, the code available for download does have all of the MySQL specific statements used.[/size][*][size="3"][size="4"]Code Typo: Page 249 -

In url manager configuration, site/commentFeed is printed, but it should be just comment/feed:




				'commentfeed'=>array('comment/feed', 'urlSuffix'=>'.xml', 'caseSensitive'=>false),

				'<pid:\d+>/commentfeed'=>array('comment/feed', 'urlSuffix'=>'.xml', 'caseSensitive'=>false),




[/size][/size][*][size="4"]Typo: Page 210 -

In the 3rd paragraph down, it refers to the view file as show.php but should be view.php.[/size][*][size="4"]Code/Yii version mismatch: Page 210 - The example 1/2 way down the page of creating the link is not consistent with the other menu items. It should be:

$this->menu[] = array('label'=>'Add User To Project', 'url'=>array('adduser', 'id'=>$model->id)); 

[/size][size=“4”] rather than using the CHtml::link method directly. (this format will still work, but is not consistent with the other menu items)[/size][][size=“3”][size=“4”]Code Typo: Page 91 - In the listed testCreate() function, the project column fields names need to be updated: [/size][/size][size=“4”]‘createTime’ should be ‘create_time’, ‘createUser’ should be ‘create_user_id’, ‘updateTime’ should be ‘update_time’ and ‘updateUser’ should be ‘update_user_id’. The code still works and the test passes because the database will accept null values for these. But the names should be corrected.[/size][][size=“4”]Code comment at the bottom of page 205 incorrectly references password, when it should be “role” - code is correct, but the code comment is not accurate Should be [/size][color="#880000"][size=“2”]// username and role are required[/size][/color][][size=“4”][color="#1c2837"]Typo - [/color][color="#1c2837"]Page 113[/color] [color="#1C2837"]First paragraph under the heading “Adding a Filter”, last sentence.[/color] [color="#1C2837"]IssueCcontroller should read: IssueController [/color][/size][][color="#1c2837"][size=“4”]Code Typo - Page 204 - in the testUserProjectAssignment() test method, ‘project1’ is incorrectly referenced, as it should be ‘project2’. The correct method is:[/size][size=“2”]

public function testUserProjectAssignment()


  //since our fixture data already has the two users assigned to project 1, we'll assign user 1 to project 2





Page 233 :


should be


Page 296 :



is missing a )

Should be :


Chapter 3, page 46/47

If using Yii 1.1.7, the Selenium test will hang on the Contact and Login screens, even though the text on the browser screen looks okay.

From other thread postings, it looks related to Yii 1.1.7 enabling client-side Javascript validation by default now.

This can be worked around for this example by editing the following two files:



Change the "enableClientValidation" parameter (one in each file) to a value of "false". Tests should now complete.

EDIT: Also, to prevent IE errors when running tests on a Linux system, delete the line in .../protected/tests/phpunit.xml that references the IE browser. When I deleted this and just left the line referencing the Firefox browser, all my test errors went away.

Another, (I think) better approach other than the one with disabling client side validation (why would you do that? since Selenium should be built to test anything (including JS validation)):

  1. If you enabled nice URLs make sure you change the way the contact page gets called (you can use something similar to the way login gets called:



  1. Change




on the login and submit buttons respectively (don’t change the


that is supposed to log you in though, only change the one that is supposed to throw a validation error);

  1. You can use the PHP function


to delay some parts of the execution to gain a better perspective over what gets called and when.

I still had problems with IE9 throwing weird script errors when Selenium opened it, didn’t struggle to fix this yet, Chrome and FF4 work like a charm under x64 Se7en.

I hope I got everything you have to do because I struggled a bit with it and tried multiple things

Hi Jeff. I’m still fairly new to PHP and web development in general and taking it one step at a time. I love the long tutorial format of your book and I’m working through it from start to finish. After that I’ll look at building my own app with Yii. (we use it in work for a frontend of a large ecommerce site and it was my first exposure to a framework, so even though I’m not on that project anymore, I’m gonna stick with yii as a “first step” to learning how frameworks work.)

Anyway, your book is really helping me along the way but I thought I would let you know I ran into a spot of trouble on page 120 when trying to enter the SQL command (at the command line and in PHPMyAdmin):

INSERT INTO ‘tbl_project_user_assignment’ (‘project_id’, ‘user_id’) VALUES (1,1), (1,2);

I got syntax errors reported. So I tried:

INSERT INTO tbl_project_user_assignment (project_id, user_id) VALUES (‘1’,‘1’), (‘1’,‘2’);

…and the insert worked. I don’t really know if that’s an error in the book but it threw me for a few minutes. Perhaps you could clarify and delete this post if neccessary. Keep up the great work and I’ll be buying your next book on yii too :wink: as I love your writing style.

Bye for now,


On page 134 Theres a block of code and in the middle (still in code font) is "And also this test:" which should obviously not be included in the code block like that. Cheers.

in page 222, the code added to view/issue/view.php,

<div id="comments">

<?php if($model->commentCount>=1): ?>


   &lt;?php echo &#036;model-&gt;commentCount&gt;1 ? &#036;model-&gt;commentCount . '

comments’ : ‘One comment’; ?>


&lt;?php &#036;this-&gt;renderPartial('_comments',array(


)); ?&gt;

<?php endif; ?>

<h3>Leave a Comment</h3>

<?php if(Yii::app()->user->hasFlash(‘commentSubmitted’)): ?>

&lt;div class=&quot;flash-success&quot;&gt;

   &lt;?php echo Yii::app()-&gt;user-&gt;getFlash('commentSubmitted'); ?&gt;


<?php else: ?>

&lt;?php &#036;this-&gt;renderPartial('/comment/_form',array(


)); ?&gt;

<?php endif; ?>


at the bottom, the variable $comment is not defined. I havn’t figured out what’s the right variable to put there?

If I replace it with $model->comments, I will get an error

PHP Fatal error: Call to a member function isAttributeRequired() on a non-object in /var/www/html/yii/framework/web/helpers/CHtml.php on line 1166

The book itself says:

It was frustrating to waste time there and then eventually find after googling around that the author is collecting corrections in this forum rather than in the support page his book says we should refer to.

Maybe I should submit a correction of Page 4 to PACKT’s support so that they put an errata on their support page.


I’ve finished reading this book lately - from start to finish. Rarely do I have the time to invest, but this time I just took the time for that :slight_smile: .

Following is my list of feedback, mostly typos etc but a few comments as well.

I haven’t checked if those are identified yet - forgive me in advance. I’m about to submit this errata to Packet Publishing. They should know too, despite voices saying things along the line of “its a lost battle”.

Also, I’d like to comment that I liked the book a lot. I think its very good as a Yii beginner’s book. Even if it has some issues and at least to me, getting the code to work on later chapters was problematic (I noted about this below…) its explanations are very good, its coverage is excellent, its depth is also good - not too much, not too shallow. Just to get intro into TDD with Yii was worth the purchase of the book. I’ll submit my review of it in Amazon as well.


• pg 106, the big notice paragraph:I think the right magic function that relates to firing the ‘non-defined’ getOptions() method is __call() and not __get(). Yes, __get() is being used by Yii as well, when dereferencing AR model attributes that are not even defined in “our” model class but that’s not the case at hand.

• pg. 109, second paragraph (starts with “This line is using the CActiveForm::labelEx()…”. On the second line’s beginning there’s an extra “a” (seems like extra to me).

• pg. 118 - a link to the project ‘view’ view was added to create an issue for that project. all nice and dandy but the link to create a new issues that appears in multiple other issue-views needs to be commented out.

• pg 129. Yes, this actionView() code section has many mentions on the web. obviously - its faulty. I wonder why its not listed on the official errata page when so much time has passed since the error has been reported. i used actionView($id) (as it was from previous steps of the apps) and therefore simply used “array(’:projectId’ => $id),…” on the line that caused the problem.

• pg. 202 second bullet, mentions table "tbl_project_use_assignment". Should be "tbl_project_user_assignment".

• pg. 202 : this is a suggestion rather than typo or the like: the book isn’t taking a tutorial with exercises approach so I would have slightly changed the approach of the text to lightly mention the option of implementation by the reader before reading the implementation ahead.

• chapter 9: beginning this chapter, I was unable to make your supplied code work with your supplied schema. By “supplied” I refer to what is available for download from Packet Publishing site. Every chapter’s material should be working on its own and by chapter 9, where i dropped my old code in favor of your code (for reasons i describe in next issue), I was unable to make the code + (your) DB sing along. There was some problem in feeding in new projects - the create_user_id wasn’t updated which led to other problems along the way. Due to time constraints I didn’t debug this. Assuming that its not my fault, IMHO, you have to make sure that each chapter’s material is self contained and “decoupled” from previous chapter’s material if there’s such a dependency. In specific - the data fed in previous chapters should not be relied upon in subsequent chapters. I’m not sure this is directly causing the problem I faced but In the supplied schema file there’s only a couple of user’s created and previous chapter’s data was dropped, which led indirectly to a problem when creating new data (projects, issues…).

• Regarding the trackstar application database schema, I think that since this book is for Yii newcomers you should drop the tbl_* prefix where it was used in some tables names. Keep it simple and appropriate for the beginner nature of the learning state. I think that there’s no need to overload the user with table name prefixes. That’s an easy piece of the puzzle to catch up with later when the need arise. Its a nag to add the ‘tbl_’ prefix while using the book and querying using command line mysql client… .

• pg. 227, first paragraph. It says there that “the second parameter will allow us… to display all comments for a project…”. That’s not accurate. It will allow us to display a limited number of comments based on given $limit var, with defautl number of such comments as defined in the first parameter - $limit.

• pg. 230, first disc-bullet - same comment as above - there’s no “get ALL comments” but rather "get all comments based on the default ‘limit’ (in findRecentComments()).

• pg. 228, first quoted code section: It says “…with(‘issues’)” while I think it should be “with(‘issue’)” as the relation name defined in Comment class is issue and not issues (singular vs. plural).

• pg. 233, the sentence right before the second code block: should state the path of the widget view as protected/components/view/recentComment.php and not renderComments.php. Similarly, in the bottom paragraph, it states the widget name to be RenderComments while its RecentComments.

• pg. 246, line 6 before page end - there’s “set the set the”. one “set” of “set the” should be deleted :slight_smile: .

• pg. 247, second paragraph: URL has a typo in the form of a mistyped space char:" localhost/trackstar /index.php…/ (note the bad space char…).

[size="5"]¡This is an important one![/size]

On Page 207, code says:

public function actionAdduser()


        $form=new ProjectUserForm;

        $project = $this->loadModel();

And it should be:

public function actionAdduser($id)


        $form=new ProjectUserForm;

        $project = $this->loadModel($id);

I am starting to work through this book. I have the recommended Yii version 1.1.2 but which versions of PHPunit and Selenium should be used for maximum compatibility/least pain? (I assume it would be best to use the versions that were active back when yii-1.1.2 was current?)

(All required software recommended versions should be posted in the first post here, yes?)

Also: Is Jeff still around here?

So far, loving yii!

RE 11-NOTE: the code available for download from the packt site doesn’t have any sql scripts at all. Is there another source for the code?

You can download from github:

I believe the versions used at the time of writing (now 2 years ago) were

PHPUnit 3.5.3


Selenium Server 1.0.3

FYI, I have just now completed all first drafts of a 2nd Edition of this book. The Second Edition will correct all of the errata published in the first book as well as brings everything up-to-date with latest version of Yii 1.1.12. Hopefully it will be released within the next month.

I know it’s not like you have any control over what the publishers do once they have the material, but we’re a month on now from this last statement, and I’m sure I’m not the only one checking this thread (and board) almost daily for news of an updated release.

As a resource it is tremendous, and a much-needed helping hand into Yii, but I desperately need current-version examples so I can understand what’s going on under the hood.

You could use following IssueController::loadModel() method instead of one mentioned on page no. 231

public function loadModel($id, $withComments=false)






				$model = Issue::model()->with(array('comments' => array('with' => 'author')))->findbyPk($id);




				$model = Issue::model()->findbyPk($id);



		if($model === null)

			throw new CHttpException(404, 'The requested page does not exist.');

		return $model;


along with call to the actionView() method as -

$issue=$this->loadModel($id, true);

Page 220

public function actionView()










Should be:

public function actionView($id)










I found out that you can already buy the book in a "RAW" version directly from the publisher.

The book title changed to: Web Application Development with Yii and PHP

Here is the link:

Did they deliver it? That sites looks like a pre-order- with delivery (hopefully) sometime in December 2012.