Returning To Page With Pagination

Hi,

I am trying to redirect the update page to the admin management page with the correct pagination URL.

So the work flow is like this.

  1. index.php/image/admin?Image_page=9

  2. Click on a record to update

    index.php/image/update/87

  3. On save, redirect back to

    index.php/image/admin?Image_page=9

I have got the logic working of redirecting back to a Image_page number, but I am using the image id to determine the page number.

So like ceil(PICTURE ID/10), since the pagination is set up to have ten images per page and at the moment, the divide by ten assumption holds, but as images are deleted it doesn’t.

So my question, how can I get Image_page number on the update page?

I had some success using


Yii::app()->request->urlReferrer

but for some reason the Image_page=9 is not set when I try use it.

Is there are better way (not to mention how handy it would be in general), to pass variables / get / post data between pages?

Cheers!

Dear Friend

I hope the following is helpful.

Model Box




public function actionUpdate($id)

	{

		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


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

		{

			$model->attributes=$_POST['Box'];

			if($model->save())

			       { $arr=array();

			        $boxes=Box::model()->findAll();

			        foreach($boxes as $box) 

			           $arr[]=$box->id;

			        $pos=array_search($model->id,$arr);

			        $page=ceil(($pos+1)/10);//10 indicates pagesize

				//$this->redirect(array('view','id'=>$model->id));

				$this->redirect(array('admin','Box_page'=>$page));}

		}


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

			'model'=>$model,

		));

	}




It is assumed that you have not employed any default sorting in search method of model.

Thank you for the prompt reply, I will give this a try in the morning when I get to work. Very much appreciated :)

Hi,

This code worked great!

It feels like it should be done by actually passing the Image_page get number instead of having to divide by ten though. Or is this the preferred way of doing it?

Again thank you very much :)

UPDATE

I do like your method because it works even if you update an image via some other method. It redirects to where that image is on the right pagination page.

Kudos to you!