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
Page 1 of 1
how to redirect and add # in the end
#2
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
#3
Posted 14 April 2012 - 04:39 PM
RedRabbit, 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?
#4
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
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
#5
Posted 14 April 2012 - 05:04 PM
yes i want to redirect.
and tnx it works;
its kind of a hack but it works
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
#6
Posted 14 April 2012 - 05:14 PM
It doesn't even need to be that hacky...
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.
$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
#7
Posted 15 April 2012 - 02:40 AM
thank you
and you forget the array(for anyone in the future that gonna search for that
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";
Share this topic:
Page 1 of 1

Help













