Reputation: 340
I get Undefined variable: user
error in my controller:
And this is my controller:
public function actionduration()
{
if (isset($_POST['W'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Week();
}
else if (isset($_POST['M'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Month();
}
else if(isset($_POST['S'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Six();
}
else if(isset($_POST['Y'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Year();
}
//print_r($user);
$this->layout='main2';
//$layout='//layouts/main1';
$this->render('edit1', array('user'=>$user));
}
Upvotes: 0
Views: 631
Reputation: 2885
Declare $user
in starting.As your $user is not getting set in any if else statement.
Try this:
public function actionduration()
{
$user="";
$this->layout='main2';
if (isset($_POST['W'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Week();
}
else if (isset($_POST['M'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Month();
}
else if(isset($_POST['S'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Six();
}
else if(isset($_POST['Y'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Year();
}
$this->render('edit1', array('user'=>$user));
}
Or You Can create one more else in last :
public function actionduration()
{
if (isset($_POST['W'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Week();
}
else if (isset($_POST['M'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Month();
}
else if(isset($_POST['S'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Six();
}
else if(isset($_POST['Y'])&&isset($_POST['Nodelist']))
{
$user = Sensor::model()->Year();
}
else
{
$user="";
}
//print_r($user);
$this->layout='main2';
//$layout='//layouts/main1';
$this->render('edit1', array('user'=>$user));
}
Upvotes: 1
Reputation: 1579
This means your code is not initializing $user. Do a test to check if any of the if conditions are returning true. Looks like they all return false.
Upvotes: 0