Errata

Although both author and PACKT Publishing have taken every care to ensure the accuracy of book content, mistakes do happen. If you find a mistake in the book—maybe a mistake in the text or the code—we would be grateful if you would report this. If it will be confirmed it will be listed at this page.

If you're not sure if it's errata or not, you can open a new thread at Yii framework forum.

The following is the list of errata for all the book editions available. Thanks for your reports.

Second edition errata

Page Current Should be
17 second can be used to prevent calling all other, not yet executed handlers, by setting it to false. second can be used to prevent calling all other, not yet executed handlers, by setting it to true.
21 curl_close($url); curl_close($curl);
29 $list->add('java') $list->add('java');
29 $anotherList = new CList(array('python', 'ruby'));
$list->mergeWith($anotherList);
$list->setReadOnly(true);
$anotherList = new CList(array('python', 'ruby'), true);
$list->mergeWith($anotherList);
44 echo $this->createUrl('website/page', 'alias' => 'about'); echo $this->createUrl('website/page', array('alias' => 'about'));
44 echo $this->createAbsoluteUrl('website/page', 'alias' => 'test'); echo $this->createAbsoluteUrl('website/page', array('alias' => 'test'));
44 CWebApplication:: createUrl CWebApplication::createUrl
58,59 $this->redirect('post/index'); $this->controller->redirect('post/index');
60 $this->redirect($this->redirectTo); $this->controller->redirect($this->redirectTo);
80 jQuery('body').delegate('#yt0','click',function() jQuery('body').on('click','#yt0',function()
85 <h2><?php echo $keyword?> events</h2> <h2><?php echo $object?> events</h2>
85 $.each(json.data,function(){ $.each(json,function(){
86 $this->widget("ext.yiicookbook. EYiiCookbook" $this->widget("ext.yiicookbook.EYiiCookbook"
107 handlePut and handlePost signatures and implementations should be swapped.
114 As mentioned previously, the that backend conforms to REST. As mentioned previously, the application backend conforms to REST.
114 put is create, post is update, get is read, and delete is delete post is create, put is update, get is read, and delete is delete
119 Creating a custom input widget with C Input Widget Creating a custom input widget with CInputWidget
129 array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()) array('verifyCode', 'captcha', 'allowEmpty'=>!(CCaptcha::checkRequirements()&& Yii::app()->user->isGuest))
132 $rand = mt_rand(1, $code-1); $rand = mt_rand(min(1, $code-1), max(1, $code-1));
149 such as assertTrueassertFileExists such as assertTrue, assertFileExists
242 When you are running an application and passing a route such as api/get prior to executing ApiController::actionGet Yii, check if controllerMap defined. When you are running an application and passing a route such as api/get, prior to executing ApiController::actionGet Yii checks if controllerMap is defined.
247 if (substr($file, - 1) == DIRECTORY_SEPARATOR)SEPARATOR if (substr($file, -1) == DIRECTORY_SEPARATOR)
259, 262 throw new CException(Yii::t('ext','View file "$sourceFile" does not exist.', array('{file}'=>$sourceFile))); throw new CException(Yii::t('ext','View file "{file}" does not exist.', array('{file}'=>$sourceFile)));
333 As we can see, a criterion allows As we can see, a criteria allows

Looking for the first edition?

First edition errata

Page Current Should be
foreword thorough a review a thorough review
16 // $event argument here is CEvent instance that
// was created passed when an event method was called.
// This time it was happened inside of
// CModel::afterValidate().
17 second can be used to prevent calling all other, not yet executed handlers, by setting it to false. second can be used to prevent calling all other, not yet executed handlers, by setting it to true.
21 $url = $this->getUrl($songTitle); $url = $this->getRequestUrl($songTitle);
23 throw new ChttpException(400); throw new CHttpException(400);
33 if(Yii::app()->request->isAjaxRequest)s if(Yii::app()->request->isAjaxRequest)
41, 45 // uncomment the following to enable URLs in path-format
/*
// uncomment the following to enable URLs in path-format
43 echo $this->createUrl('website/page', 'alias' => 'about'); echo $this->createUrl('website/page', array('alias' => 'about'));
43 echo $this->createAbsoluteUrl('website/page', 'alias' => 'test'); echo $this->createAbsoluteUrl('website/page', array('alias' => 'test'));
47 http://example.com/posts/ASC
// success
http://example.com/posts/ASC
58 (2nd) $this->redirect('post/index'); $this->controller->redirect('post/index');
59 $this->redirect('post/index'); $this->controller->redirect('post/index');
66 $this->renderPartial('////common/youtube', array( $this->renderPartial('//common/youtube', array(
72
77 In the index action, we use In the index view, we use
81 Unfortunately Facebook changed APIs slightly and the "Managing assets" recipe got broken. The way assets are managed in the recipe is still correct.
82 'loadingImageUrl' => $this->loadingImageUrl,, 'loadingImageUrl' => $this->loadingImageUrl,
83 </p><p>"+this.location </p><p>"+this.location+
87 Yii::app()->registerCss('myCSS', 'body {margin: 0; padding: 0}', 'all'); Yii::app()->clientScript->registerCss('myCSS', 'body {margin: 0; padding: 0}', 'all');
87 Yii::app()->clientScript->registerScript('myscript', 'echo"Hello, world!";', CClientScript::POS_READY); Yii::app()->clientScript->registerScript('myscript', 'alert("Hello, world!");', CClientScript::POS_READY);
93 Yii::app()->clientScript->registerScript('appConfig', "var config = ".$config.";",CClientScript::POS_HEAD);); Yii::app()->clientScript->registerScript('appConfig', "var config = ".$config.";",CClientScript::POS_HEAD);
96 Now, the pretected/views/task/index.php view: Now, the protected/views/task/index.php view:
104 then you get Please upload file first then you get Please upload a File
109 $files=CUploadedFile::getInstance($model,'file'); $files=CUploadedFile::getInstances($model,'file');
116 return $code-$rand.»+».$rand; return $code-$rand."+".$rand;
117 public $valueTo; public $valueTo;
protected function hasModel()
{
  return $this->model instanceof CModel && $this->attributeFrom!==null && $this->attributeTo!==null;
}
129 '~\[~\[b\](.*)\[/b\]~i' => '<strong>$1</strong>', '~\[b\](.*)\[/b\]~i' => '<strong>$1</strong>',
142 cd path/to/checked/out/code/tests/ phpunit --coverage-html reports framework/base cd path/to/checked/out/code/tests/
phpunit --coverage-html report framework/base
148 Use Gii to create models actor and field tables Use Gii to create models actor and film tables
152 With actionSql, we do the same except two things: we pass SQL directly instead of adding its parts one by one and we escape values manually with Yii::app()->db->quoteValue before using them in the query string. With actionSql, we do the same except we pass SQL directly instead of adding its parts one by one. It worth mentioning that we should escape parameter values manually with Yii::app()->db->quoteValue before using them in the query string.
153 Link to database.ar in “There's more…” section listed twice.
162 By using a regular expression, we replace everything that looks like a URL with a link that uses this URL and calls the parent implementation, so real events are raised properly. By using a regular expression, we replace everything that looks like a URL with a link that uses this URL and are calling the parent implementation, so real events are raised properly.
167 $models = Snippet::model()->findAll(); $models = Snippet::model()->findAll($criteria);
171 We need to store these, as we need them when we edit the the snippet. We need to store these, as we need them when we edit the snippet.
173
protected function beforeValidate()
	{
	  if($this->getIsNewRecord())
		$this->created_on = time();

	  $this->modified_on = time();

	  return true;
	}
protected function beforeValidate()
	{
	  if($this->getIsNewRecord())
		$this->created_on = time();

	  $this->modified_on = time();

	  return parent::beforeValidate();
	}
199 itemView specifies a view partially used to render each data row. itemView specifies a view partial used to render each data row.
208 This is the exact copy of the method named CDataProvider. This is the exact copy of the same named method from CDataProvider.
214 To use fixtures, the test class should be inherited from CDbTestCase and have public $fixtures declared: To use fixtures, the test class should be inherited from CDbTestCase and have protected $fixtures declared:
243 Now we need to connect view rendered to application. Now we need to connect view renderer to application.
260 Run the index action again and check protected/runtime/error. Run the index action again and check protected/runtime/errors.
316 Therefore, if we add indexes for tbl_post.status and tbl_post.create_time, it will improve SELECT performance, as shown in the following screenshot: Therefore, if we add indexes for tbl_comment.status and tbl_comment.create_time, it will improve SELECT performance, as shown in the following screenshot:
342 Now, we have a custom directory named protected. Now, we have a custom directory named app.
350, 352, 355, 356 protected/configs protected/config
356 else if($_SERVER['HTTP_HOST']=='example.local') else