Yii Framework Forum: Redirect Problem - Yii Framework Forum

Jump to content

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

Redirect Problem Rate Topic: -----

#1 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 23-January 12
  • Location:Paris - France

Posted 07 March 2013 - 06:08 AM

Hi,
i've got problem using redirect at the end of a controller.

In a view, i want to use an action closed to delete, called with a link:
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider, 
...
     array(
      	'class'=>'CButtonColumn',
            'template' => '{detaches}{notes}',
            'buttons' => array(
    	        'detaches' => array(
		  'label'=>'Detaches',   
                  'imageUrl'=>'', 
                  'imageUrl'=>Yii::app()->request->baseUrl.'/images/detaches.ico',
                  'url'=>'Yii::app()->createUrl("/RelStudentSemester/detache", array("id"=>$data->primaryKey,"rattrapage"=>$data->group->rattrapage_ind, "group_id"=>$data->group_id))',
                ),
...


This is my action code:
	/**
	 * Détache un étudiant d'un groupe
	 * @param integer $id ID du RelStudentSemester à modifier
	 * @param text $rattrapage indique si on est sur un groupe de semester ou de rattrapage
	 * @param integer $group_id indique le groupe à réafficher à la fin du traitement
	 * 	 * 	 */
	public function actionDetache($id, $rattrapage, $group_id)
	{
		$rel=RelStudentSemester::model()->findByPk($id);
		if($rattrapage == '1') // on est sur un groupe de rattrapage
		{
			$rel->group_rattrapage = 0;
			$rel->save();
		}
		else // groupe de semestre
		{
			$rel->group_id = 0;
			$rel->save();
		}
		$this->redirect(array('/groups/view', array("id"=>$group_id)));
	} // fin actionDetache


But the redirect didn't work:
Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/GL1/protected/controllers/RelStudentSemesterController.php:6) 


I've check the output on line 6 of my controller, it's just the begin of the file (it contains "<?php").
Can someone help me?
0

#2 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 07 March 2013 - 07:00 AM

View Postragua, on 07 March 2013 - 06:08 AM, said:

Hi,
i've got problem using redirect at the end of a controller.

In a view, i want to use an action closed to delete, called with a link:
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider, 
...
     array(
      	'class'=>'CButtonColumn',
            'template' => '{detaches}{notes}',
            'buttons' => array(
    	        'detaches' => array(
		  'label'=>'Detaches',   
                  'imageUrl'=>'', 
                  'imageUrl'=>Yii::app()->request->baseUrl.'/images/detaches.ico',
                  'url'=>'Yii::app()->createUrl("/RelStudentSemester/detache", array("id"=>$data->primaryKey,"rattrapage"=>$data->group->rattrapage_ind, "group_id"=>$data->group_id))',
                ),
...


This is my action code:
	/**
	 * Détache un étudiant d'un groupe
	 * @param integer $id ID du RelStudentSemester à modifier
	 * @param text $rattrapage indique si on est sur un groupe de semester ou de rattrapage
	 * @param integer $group_id indique le groupe à réafficher à la fin du traitement
	 * 	 * 	 */
	public function actionDetache($id, $rattrapage, $group_id)
	{
		$rel=RelStudentSemester::model()->findByPk($id);
		if($rattrapage == '1') // on est sur un groupe de rattrapage
		{
			$rel->group_rattrapage = 0;
			$rel->save();
		}
		else // groupe de semestre
		{
			$rel->group_id = 0;
			$rel->save();
		}
		$this->redirect(array('/groups/view', array("id"=>$group_id)));
	} // fin actionDetache


But the redirect didn't work:
Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/GL1/protected/controllers/RelStudentSemesterController.php:6) 


I've check the output on line 6 of my controller, it's just the begin of the file (it contains "<?php").
Can someone help me?


change the code of redirect
$this->redirect(array('/groups/view',"id"=>$group_id));

0

#3 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 23-January 12
  • Location:Paris - France

Posted 07 March 2013 - 07:59 AM

Thanks for the reply Balu, but i'm still having the same problem with the redirect.
0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 04-March 10
  • Location:UK

Posted 07 March 2013 - 08:49 AM

Make sure there's no whitespace or other content in your controller file before the opening PHP tag.
0

#5 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 773
  • Joined: 02-July 10
  • Location:Central Poland

Posted 07 March 2013 - 08:49 AM

check your files if they do not contain UTF-8 BOM header. Not every text editor will show it, but some add few bytes at the beginning of UTF8 coded files such "header"
red
0

#6 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 23-January 12
  • Location:Paris - France

Posted 07 March 2013 - 09:36 AM

Thanks a lot Keith and Redguy,
my problem is now solved after deleting the firsts lines of the controller.
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