Yii Book - 2nd Edition - Found Errata

"A Man's Errors Are His Portals Of Discovery."
James Joyce

If you find any errors or issues with the book as you are reading along, please don't hesitate to let me know. I'll add a correction to this page to help out other readers and work with Packt publishing to correct them in the printed versions.

Chapter 2 - Page 30

Towards the bottom of the page, in the section One final step it suggests code for the hello.php view file as:
<?php <h1>Hello World!</h1>
However, the beginning PHP tag is not needed, just the html snippet:
<h1>Hello World!</h1>

This is a printing typo. You can always refer to the code bundle for a reference that does not suffer from such printing errors. - Thanks to scrupulous reader Mark D. for pointing out this typo.


Chapter 2 - Page 37

Towards the top of the page, in the section Getting a little help from Yii CHtml it suggests code for the hello.php view file as:
CHtml::link('Goodbye'array('message/goodbye'));
However, a comma is missing between the 'Goodbye' and the array(). It should read:
CHtml::link('Goodbye', array('message/goodbye'));

This typo was introduced during the printing. You can always refer to the code bundle for a reference that does not suffer from such printing errors. - Thanks again to scrupulous reader Mark D. for pointing out this typo.


Chapter 3 - Page 53

Small typo close to the bottom of the page. It says:
Change the assertEquals(true) statement...
But should read
Change the assertTrue(true) statement...
-Thanks to scrupulous reader and Yii forum member nammae for pointing out this typo.


Chapter 5 - Page 98

Small typo pertaining to the class from which IssueController extends. The printed version has:
class IssueController extends CController
But it should be:
class IssueController extends Controller

This typo was introduced during the printing. You can always refer to the code bundle for a reference that does not suffer from such printing errors. - Thanks to scrupulous reader Roger for bringing this typo to our attention.


Chapter 8 - Page 188

At the bottom of the page, in the code declaration for adding a foreign key on the comment table, there is a missing ending quote character on the first of the two RESTRICT arguments. It is printed as "RESTRICT, but should be "RESTRICT". The entire line should be:
$this->addForeignKey("fk_comment_owner", "tbl_comment", "create_user_id", "tbl_user", "id", "RESTRICT", "RESTRICT");

This typo was introduced during the printing and is not part of the associated code bundle. You can always refer to the code bundle for a reference that does not suffer from such printing errors. - Thanks once again to scrupulous reader Mark D. for pointing out this typo.


Chapter 8 - Page 188 and 189

At the bottom of page 188, and the top of page 189 the code comments for the two foreign key declarations reference the wrong table name.
//the tbl_issue.create_user_id is a reference to tbl_user.id
should refer to the comment table as such
//the tbl_comment.create_user_id is a reference to tbl_user.id
And
//the tbl_issue.updated_user_id is a reference to tbl_user.id
should also be referencing the comment table as such
//the tbl_comment.update_user_id is a reference to tbl_user.id.

Thanks to scrupulous reader David for pointing out this typo.


Tip (An Application Improvement)
Chapter 7 - Page 178-179

This is not exactly a book error, but in order for the application to allow a user to create multiple projects as well as assign the same users to multiple projects within the same role, we need to make a small change to the code when associating a user to a role upon project creation. We need wrap the role assignment in an if statement to determine whether or not the user has already been added to the RBAC hierarchy for that role.
if(!$auth->isAssigned($this->role, $this->_user->id))
{
$bizRule='return isset($params["project"]) && $params["project"]->allowCurrentUser("'.$this->role.'");';
$auth->assign($this->role,$this->_user->id, $bizRule);
}

This is correct in the code but was not explicit in the printed code snippet.


Tip (An Application Improvement)
Chapter 7 - After RBAC implementation

This is not exactly a book error, but once we change to using our RBAC structure, we need to change our simple access rules, defined in protected/components/Controller.php to use the role rather than name when checking if the user is an admin. So in our allow rule, we need to change:
'users'=>array('admin'),
to
'roles'=>array('admin'),

This is correct in the code but was not explicit in the printed code.