Welcome Guest, Not a member yet? Register   Sign In
URI class doesn’t recognize #anchors
#3

[eluser]coolfactor[/eluser]
My current solution involves intercepting the call to Router::_set_request() with the following:


Code:
function _set_request($segments = array()) {
    if ($seg = array_pop($segments)) {
        $i = strpos($seg, '#');
        if ($i !== FALSE) {
            list($seg, $this->uri->anchor) = explode('#', $seg);
        }
        if ($seg) {
            $segments[] = $seg;
        }
    }
    return parent::_set_request($segments);
}

Basically, it checks to see if "#" exists in the last segment, extracts the anchor name into $this->uri->anchor, restores the last segment without the anchor, and then passes control on to the stock _set_request() function to continue processing.

The code gracefully handles routes with and without a trailing slash:
Code:
/page/info#mission
/page/info/#mission

The URI class would need to be adjusted to utilize the $this->uri->anchor property.


Messages In This Thread
URI class doesn’t recognize #anchors - by El Forum - 07-27-2008, 11:29 PM
URI class doesn’t recognize #anchors - by El Forum - 07-28-2008, 12:01 AM
URI class doesn’t recognize #anchors - by El Forum - 07-28-2008, 12:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB