Yii Framework Forum: how to redirect and add # in the end - Yii Framework Forum

Jump to content

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

how to redirect and add # in the end Rate Topic: -----

#1 User is offline   amiramir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 09-January 12

Posted 14 April 2012 - 10:31 AM

i want to redirect my page to this url:
http://example.com/i...ts/update&id=28#unieq28

i tried a lot of ways with $this->redirect they all replace the # with %23

tnx
0

#2 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 14 April 2012 - 04:25 PM

As far as I know, you can't server-side redirect to the hash part of a link - the hash part is only managed by the client (browser), so while you can generate a link including a hash, that will work if a user clicks on it in his browser (because the browser will load the relevant page then look for the anchor in it), server side you can only redirect to a page and not within that page. This is inherent in HTTP/HTML and nothing to do with Yii.
Rupert
0

#3 User is offline   amiramir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 09-January 12

Posted 14 April 2012 - 04:39 PM

View PostRedRabbit, on 14 April 2012 - 04:25 PM, said:

As far as I know, you can't server-side redirect to the hash part of a link - the hash part is only managed by the client (browser), so while you can generate a link including a hash, that will work if a user clicks on it in his browser (because the browser will load the relevant page then look for the anchor in it), server side you can only redirect to a page and not within that page. This is inherent in HTTP/HTML and nothing to do with Yii.

sorry but i think you did not understand me
i have a website in one of my page i have a div with id="example"
now if i do something like <a href="www.mywebsite.com/projects/index#example" /> it works great
i want to do the same in yii so i tried:
 $this->redirect(array('projects/view#example'));

and it not working
so how do i make a link in yii and add in the end the # symbol?
0

#4 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 14 April 2012 - 05:01 PM

$this->redirect (referring to the Controller) is used to automatically redirect an incoming request to a different url, which is a server-side action (not generating a clickable link on a web page), so cannot involve the hash part of the url.
If you mean that you want to generate a link in your view that the user can then click on, which should include a hash, then that is a different question.
I haven't seen any parameters in createUrl for including a hash part, but at the very worst, in your view you would do something like
echo $this->createUrl('projects/index').'#example';

Rupert
1

#5 User is offline   amiramir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 09-January 12

Posted 14 April 2012 - 05:04 PM

yes i want to redirect.
and tnx it works;
                    
$url = Yii::app()->createUrl('projects/view')."&id=$model->projectID#uniqe_$id";      

$this->redirect($url);

its kind of a hack but it works
0

#6 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 14 April 2012 - 05:14 PM

It doesn't even need to be that hacky...
$url = Yii::app()->createUrl('projects/view', 'id' => $model->projectID)."#uniqe_$id";

should give you the same result, as well as allowing you to change your url scheme later without recoding if necessary (apart from the hash fragment of course).

And yes, I suppose if you are redirecting the url via a 302 code (not an invisible redirect), that should work - I hadn't though about it like that.
Rupert
0

#7 User is offline   amiramir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 09-January 12

Posted 15 April 2012 - 02:40 AM

thank you
and you forget the array(for anyone in the future that gonna search for that
$url = Yii::app()->createUrl('projects/view',array( 'id' => $model->projectID))."#uniqe_$id";

0

#8 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 26-September 09

Posted 15 April 2012 - 05:27 PM

I am not sure if this is you're looking for...

see this thread

In short,

Yii::app()->createUrl('projects/view', 'id' => $model->projectID, '#' => "#uniqe_$id");

0

#9 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 16 April 2012 - 06:52 AM

View PostDaniel, on 15 April 2012 - 05:27 PM, said:

I am not sure if this is you're looking for...

see this thread

In short,

Yii::app()->createUrl('projects/view', 'id' => $model->projectID, '#' => "#uniqe_$id");



Good to know - I hadn't come across that before.
Rupert
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