Yii Framework Forum: Gridview - Redirect To The Same Page - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Gridview - Redirect To The Same Page Rate Topic: -----

#1 User is offline   reburg 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 15-January 13

Posted 03 February 2013 - 04:12 PM

How can I go back to the same page in GridView after updating a particular record.

For example, when I click an update icon in the button column of a row on GridView page 5 then I get redirected to page 1 after saving the record changes.

Thank you for hints.
Greetings from Austria
Ferdinand
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 03 February 2013 - 08:38 PM

Dear Friend

Here is one example.

Model:Wage,
Controller:WageController.

WageController.php
public function actionAdmin()
{
        $model=new Wage('search');
        $model->unsetAttributes();  // clear any default values         
        if(isset($_GET['Wage']))
        {
                $model->attributes=$_GET['Wage'];
        }
        Yii::app()->user->setState('grid',$_GET);//saving all the get parameters into session.

        $this->render('admin',array(
                        'model'=>$model,
                ));
}


views/wage/view.php.
Just append the following in view.php
if(Yii::app()->user->hasState("grid"))
{       
        $grid=Yii::app()->user->getState('grid');               
        $route=array("wage/admin");
        echo CHtml::link("Return to Grid",array_merge($route,$grid));
        Yii::app()->user->setState("grid",null);
}


Now you will exactly land from where you came.
It retains previous sorting and page as well.
The only drawback here is ugly looking url.

I hope I helped a bit.

Regards.
0

#3 User is offline   reburg 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 15-January 13

Posted 04 February 2013 - 07:38 AM

Thank you very much, this works perfectly. I created the link at bottom of the view and it brings me back to where I came from. Now I am happy to understand a little, how yii manages sessions.

Please can you help me, how to change also the menu link back to the admin page on this view. I am a yii beginner and I have much troubles to understand the logic and the object structure of yii ...

Please can you help me to change the menu item like that:

array('label'=>'Noten bearbeiten', 'url'=>array('admin')),


Best regards
Ferdinand
Greetings from Austria
Ferdinand
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 04 February 2013 - 09:54 AM

Dear Friend

In my case I achieved this in the followin way.

array('label'=>'Manage Wage', 'url'=>$this->createUrl('admin',Yii::app()->user->hasState("grid")?Yii::app()->user->getState('grid'):"")),


Kindly apply this in your scenario.

Regards.
0

#5 User is offline   reburg 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 15-January 13

Posted 04 February 2013 - 11:03 AM

Hi,
thank you very much.

After applying this as menu item

array('label'=>'Noten bearbeiten','url'=>$this->createUrl('admin',Yii::app()->user->hasState("grid")?Yii::app()->user->getState('grid'):"")),


I get the error

Fatal error: Cannot unset string offsets in /srv/www/yii-1.1.12.b600af/framework/web/CUrlManager.php on line 283


To find the bug easier, please look at more code of the view:

...
$params = "";
if(Yii::app()->user->hasState("grid")) {
        $params = Yii::app()->user->getState('grid');
        Yii::app()->user->setState("grid",null);
}

$this->menu=array(
	array('label'=>'Alle anzeigen', 'url'=>array('index')),
        ...
// 	array('label'=>'Noten bearbeiten', 'url'=>array('admin')),
	array('label'=>'Noten bearbeiten',
              'url'=>$this->createUrl('admin',Yii::app()->user->hasState("grid")?$params:"")),
);

...

echo CHtml::link("Zurueck",array_merge('noten/admin',$params));


Thanks in advance
Ferdinand
Greetings from Austria
Ferdinand
0

#6 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 04 February 2013 - 12:12 PM

Dear Friend

Sorry about that.

It committed a mistake.

The following is the code from my machine.

$this->breadcrumbs=array(
	'Wages'=>array('index'),
	$model->name,
);

$this->menu=array(
	array('label'=>'List Wage', 'url'=>array('index')),
	array('label'=>'Create Wage', 'url'=>array('create')),
	array('label'=>'Update Wage', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete Wage', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage Wage', 'url'=>$this->createUrl('admin',Yii::app()->user->hasState("grid")?Yii::app()->user->getState('grid'):array())),
);
?>

<h1>View Wage #<?php echo $model->id; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		'id',
		'name',
		'days',
		'hours',
	),
)); ?>

<?php

if(Yii::app()->user->hasState("grid"))
		{	
			$grid=Yii::app()->user->getState('grid');		
			$route=array("wage/admin");
			echo CHtml::link("Return to Grid",array_merge($route,$grid));
			Yii::app()->user->setState("grid",null);
		}



I appended a empty string rather than attaching an empty array in ternary conditional operator.This caused the problem.

it should be
Yii::app()->user->hasState("grid")?Yii::app()->user->getState('grid'):array() //earlier I attached an empty string.


As we are making "grid" status null, the code to create the menu should come above it before making it null.

Regards.
0

#7 User is offline   reburg 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 15-January 13

Posted 04 February 2013 - 12:45 PM

View Postseenivasan, on 04 February 2013 - 12:12 PM, said:

it should be
Yii::app()->user->hasState("grid")?Yii::app()->user->getState('grid'):array() ...

...

Thank you very much. Now it works in both ways: using a link and using a menu item!

Regards
Ferdinand
Greetings from Austria
Ferdinand
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users