How Get Full Url With Ancors?

How return current URL with anchors?

Example: I’m in page www.sitename#anchor

I want get full URL www.sitename#anchor, not www.sitename.

Yii::app()->request->getUrl() isn’t suitable for this purpose

The anchor part isn’t sent to the server by the browser, so PHP can never see it.

More info here:

http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url

If you need it, you could use javascript to send it in a separate request.

You can’t get the anchor as it is not submitted to the server. If you need it you have to do an ajax request.

PHP can’t get ancors.

Happy coding.

Maybe i don’t see simple solution.

I used extension rrgridview.

I use filters and choose one of record and go to it update.

I need to return back after i save all changes.

How can i do it, if i can’t get (easily) anchors of url?

to pass something in via the url you will need to use a GET or POST method. GET would be simplier if it isn’t sensitive information, e.g. ?id=12&sitename=something

The first step is to get the grid view to generate the correct links. You’ll want to add a new variable to each link (I use a variable named redir). So add the appropriate line of this to your grid view definition:




    ...

    'buttons'=>array(

        'update' => array(

            'url'=>'Yii::app()->createUrl(Yii::app()->controller->id."/update", array("id"=>$data->id, "redir"=>Yii::app()->controller->id."/admin"))',

        ),

        ...



Next, you’ll want to modify your controller action:




...

if($model->save()) {

  if(isset($_GET['redir']) $this->redirect($_GET['redir']);

  else $this->redirect('whatever_you_want_to_make_the_default_action');

}



This is completely untested code, YMMV.