简体   繁体   中英

Remove part of URL using PHP (Zend FrameWork)

my link is like this :

http://website.com/test1/test2/public/books/detail/page_id/number/page/2

I want to remove page and 2 and convert it to :

http://website.com/test1/test2/public/books/detail/page_id/number

I can define last part of URL with :

$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
$part = basename($uri);

or define another part like this :

$parts = Explode('/', $uri);
    $id2 = $parts[count($parts) - 2];
    $id1 = $parts[count($parts) - 1];

but I have problems to remove that

$uri = $this->serverUrl(true);    
$parts = Explode('/page/', $uri);

the $parts[0] will be the good link you want

I think, for your case, this should be in your controller:

$url = Zend_Controller_Front::getInstance()->getBaseUrl() .
"books/detail/page_id/" . $this->getRequest()->getParam('page_id');

PS: Syntax will be different if you are in a view script, in which case you should create a view helper anyway or you can do it in controller and assign to view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM