Yii - Undefined variable error when rendering view
this is my first post.
I'm new to Yii framework.
I'm having a problem now with rendering view. I get an undefined variable
error when I render Controller.
I don't understand why I get an undefined variable error although the
variable getting error is surrounded with if statement.
the code below is what I simplified my code that I'm actually working on.
Please help me out! I'd like to know the reason why Im getting an
undefined variable error and also I'd like to know how to solve this
problem.
Thanks very much in advance!!!
+++ Controller +++
class CategoryController extends Controller
{
public function actionIndex()
{
$flag = false;
if($flag){
$this->render('index', array('test'=>$flag));
}
//This causes "Undefined variable:test" Error.
$this->render('index');
//This works fine.
//$this->render('index', array('test'=>$flag));
}
}
+++ View(this is rendered with layout view. +++
<?php
if($test){
echo "$test is false";
}else{
echo "$test is true";
}
?>
No comments:
Post a Comment