Variable Undefined Inside Controller

Hi all,

i am facing pblm with the variable in the below code.

i am not able to find out evne though variable is initialised why it is undefined.plss help me asap…thnku :)

class PermdataController extends Controller

{

var $y;

public function actionSearch()

{

if(isset($_POST[‘submit’])){

if(isset($_POST[‘y’]))

{

$y = $_POST[‘y’];

$model->attributes=$_POST[‘y’];

}

}

$criteria = new CDbCriteria();

$criteria->condition = “EMPLOYER_NAME LIKE ‘:start’”;

$criteria->params = array (

‘:start’ =>$y,

);

switch($year)

{

case ‘2007’:

$dataProvider=new CActiveDataProvider

(“PermData2009”, array(‘criteria’=>$criteria,‘sort’=>array(

‘attributes’=>array(

‘CASE_NO’,‘CASE_STATUS’,

),

),

‘pagination’=>array(

‘pageSize’=>2,

),));

break;

case ‘2006’:

$$dataProvider=new CActiveDataProvider

(“PermData2009”, array(‘criteria’=>$criteria,‘sort’=>array(

‘attributes’=>array(

‘CASE_NO’,‘CASE_STATUS’,

),

),

‘pagination’=>array(

‘pageSize’=>2,

),));

break;

case ‘2005’:

$dataProvider=new CActiveDataProvider

(“permdata2005”, array(‘criteria’=>$criteria,‘sort’=>array(

‘attributes’=>array(

‘CASE_NO’,‘CASE_STATUS’,

),

),

‘pagination’=>array(

‘pageSize’=>2,

),));

break;

}

You have to access the class property of ‘y’ using ‘$this->y’ syntax. :)




class PermdataController extends Controller

{

    var $y; // ?? but why don't you use "public $y" ??


    public function actionSearch()

    {

        if(isset($_POST['submit'])){

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

            {

                // $y = $_POST['y'];

                $this->y = $_POST['y'];

                // $model->attributes=$_POST['y']; // ?? where's $model ??

            }

        }

        $criteria = new CDbCriteria();

        $criteria->condition = "EMPLOYER_NAME LIKE ':start'";

        $criteria->params = array (

            // ':start' =>$y,

            ':start' => '%' . $this->y . '%', // LIKE needs '%'s

        );

        ...