How can I redirect to an anchor? [SOLVED]

How can I redirect to an anchor?

you can do: array('controller/action', 'id'=>'123', '#'=>'anchor')

Quote

you can do: array('controller/action', 'id'=>'123', '#'=>'anchor')

not working  :(

Are you using $this->redirect(array(…)) ?

Quote

Are you using $this->redirect(array(...)) ?

That is my code:

Could you verify what is the URL generated?

echo $this->createUrl(array(…)) ?

Quote

Could you verify what is the URL generated?

echo $this->createUrl(array(…)) ?

I think it is not correct:

I think it should be like this:

and I become:

/myModule/myController/myAction/id/123#test

'#'=>'test' works with 'createUrl' not with 'redirect'

I have tried sth like this:

and the anchor does not work! the URL does not have the anchor,

but

shows the URL with the anchor!

???

my bad about createUrl().

It should work though with redirect. Check the implementation of CController::redirect() and you will see.

Quote

It should work though with redirect. Check the implementation of CController::redirect() and you will see.

This:

does not work either. Redirect just cut the anchor.

I've checked the implementation but nothing found…

I see no reason why it shouldn't work. Yii doesn't modify the provided URL before sending the redirect header.

Maybe the browser doesn't support redirecting to an anchor?

Quote

Maybe the browser doesn't support redirecting to an anchor?

It is not this… the URL does not contain the anchor, yii cut it out, but why?

Would somebody please check this …



$this->redirect(array('controller/action', 'id'=>'123', '#'=>'anchor'));


… if the anchor works.

Nope, Yii doesn't truncate that. Maybe the PHP header() function doesn't honor the anchor.

Quote

Nope, Yii doesn't truncate that. Maybe the PHP header() function doesn't honor the anchor.

Anchors work great but…

Let's say I have model 'Post', there I want to use redirect like this:



$this->redirect(array('update','id'=>'4139','#'=>'anchor'));


it works great!

Now let's say I have two models: 'Post', 'Comment', and I want to use redirect like this:

In my 'Post' view I have a button to use one action in 'Comment' controller (comment/admin). When the action is done I want to redirect back to the 'Post', using redirect and $_POST['from'] and $_POST['fromId']. It works great but not the anchor:

My view in 'Post':



echo CHtml::linkButton(CHtml::image('/images/active.png','Active'),array(


                                     'submit'=>$this->createUrl('comment/admin'),


                                     'params'=>array(


                                        'from'=>'post/update',


                                        'fromId'=>$post->id,


                                        'command'=>'active',


                                        'mod'=>'0',


                                        'id'=>$v->id


                                        ),


                                     ));


and 'admin' action in 'Comment' controller:



if($_POST['from']){


    $this->redirect(array($_POST['from'],'id'=>$_POST['fromId'],'#'=>'anchor'));                           


}


and the anchor does not work here.

it works fine with Yii 1.0.6.

Thx.