session data usage

Hi all,

  I am trying to implement session management.

I have a login page where in i am entering (username,password,society_name)

there are society_name asb[/b]

Now i have data in the tables of both society1,society2…

I am trying to filter the data and show to the user the data which should only belong to society1 or society2 by which the user login.

I am able to get the society_name that i entered at runtime by using session management.

I am trying to filter the data in controller ActionIndex function as





public function actionIndex()

	{

	$session=new CHttpSession;

  $session->open();

  $value1=$session['societyName'];


		$sessiondata = new CActiveDataProvider('Block');

        $sessiondata->attributes= Yii::app()->db->createCommand()

			->select('*')

			->from('tbl_block')

			->where('society_number=:society_number', array(':society_number'=>$value1))

			->queryRow();




		$dataProvider=new CActiveDataProvider('Block');

		$dataProvider= $sessiondata;

		// $dataProvider->unsetAttributes();  //Clear any default values

       //if(isset($_GET['Block'])) $dataProvider->attributes = $_GET['Block'];

		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}



I am not sure of this process. kindly guide me in this issue.

Is filtering done at client side or server side?

regards,

RamaKrishna.

I’m not sure how you name your variables…

but

why are you searching for society_number to be equal to society_name ?

Also, you should check your code:




   // mmm... so what is that?

  $dataProvider=new CActiveDataProvider('Block');

    $dataProvider= $sessiondata;



I would suggest:




public function actionIndex()

 {

    $session=new CHttpSession;

    $session->open();

    $societyName=$session['societyName'];


    $criteria=new CDbCriteria;

    // assuming you made a mistake with the field name

    $criteria->addCondition('society_name=:society_name');


    $criteria->params = array(':society_name'=>$societyName);


     $this->render('index',array(

                 'dataProvider'=>new CActiveDataProvider('Block', array('criteria'=>$criteria)),

                 ));

  }



Cheers

thanks antonio it started working for me now.

why do i get a ‘400 error your request is invalid’ when i click view and update in the manage page.i have enabled the access rules in my controller but still i am getting error.

thanks

ramakrishna

mmm… I think is something to do with parameter handling… Go to your controller’s update and view action and remove the parameter $id, then use $_GET[‘id’] to get that parameter within the function. If that solves the problem, then is something with your URL mapping settings