Chapter 6 pg 117

Hey Im following the book and on the part that we define that you cant create an Issue without having a project linked to it, Im having the following problem, apparently the call to filterchain is failing, where is it defined or how can I fix this?

Undefined variable: filterchain

/Users/user/Sites/yii11/trackstar/protected/controllers/IssueController.php(217)




205      public function filterProjectContext($filterChain)

206      {

207         //set the project identifier based on either the GET or POST input

208         //request variables, since we allow both types for our actions

209          $projectId = null;

210          if(isset($_GET['pid']))

211               $projectId = $_GET['pid'];

212          else

213               if(isset($_POST['pid']))

214                $projectId = $_POST['pid'];

215        $this->loadProject($projectId);

216          //complete the running of other filters and execute the requested action

217          $filterchain->run();

218      }

219 }




Stack Trace

#0 +

/Users/user/Sites/yii11/framework/web/filters/CInlineFilter.php(59): IssueController->filterProjectContext(CFilterChain)

#1 +

/Users/user/Sites/yii11/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(CFilterChain)

#2 +

/Users/user/Sites/yii11/framework/web/filters/CFilter.php(41): CFilterChain->run()

#3 +

/Users/user/Sites/yii11/framework/web/CController.php(1144): CFilter->filter(CFilterChain)

#4 +

/Users/user/Sites/yii11/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(CFilterChain)

#5 +

/Users/user/Sites/yii11/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(CFilterChain)

#6 +

/Users/user/Sites/yii11/framework/web/CController.php(283): CFilterChain->run()

#7 +

/Users/user/Sites/yii11/framework/web/CController.php(257): CController->runActionWithFilters(CInlineAction, array("accessControl", "projectContext + create"))

#8 +

/Users/user/Sites/yii11/framework/web/CWebApplication.php(277): CController->run("create")

#9 +

/Users/user/Sites/yii11/framework/web/CWebApplication.php(136): CWebApplication->runController("issue/create")

#10 +

/Users/user/Sites/yii11/framework/base/CApplication.php(158): CWebApplication->processRequest()

#11

/Users/user/Sites/yii11/trackstar/index.php(13): CApplication->run()

08 defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true); 09 // specify how many levels of call stack should be shown in each log message 10 defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,3); 11 12 require_once($yii); 13 Yii::createWebApplication($config)->run();

Edit line 217 above so it says $filterChain->run(); instead (PHP is a case-sensitive language, and you are actually referring to 2 variables above (filterchain and filterChain), one of which is undefined and used resulting to your error. :)

Awesome, I wasn’t aware of that tiny error. Thanks a lot!

hey, i have problem too at page 115 (adding some filter logic)

i’ve follow code on book. here my code,




        private $_project = null;

	protected function loadProject($project_id){

		if($this->_project === null)

		{

			$this->_project=Project::model()->findByPk($project_id);

			if($this->_project === null)

			{

				throw new CHttpException(404,'The Requested project does not exist.');

			}

		}

		return $this->_project;

	}

	public function filterProjectContext($filterChain)

	{

		$projectId = null;

		

		if(isset($_GET['pid']))

			$projectId = $_GET['pid'];

		else

			if(isset($_POST['pid'])

				$projectId = $_POST['pid'];

				

		$this->loadProject($projectId);

		$filterChain->run();

	}

	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'projectContext + create'

		);

	}

but when i try to access : http://localhost/latihan-php/trackstar/index.php/issue . i get an error 500

its anything wrong with my code?

thnks before :)