View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Controller_Front in Subdirectory Proposal
{zone-data}

{zone-data:proposer-list}
[Christopher Thompson|mailto:cxthompson@charter.net]
{zone-data}

{zone-data:revision}
1.1 - 1 August 2006: Updated from community comments.
{zone-data}

{zone-data:overview}
Allow the Front Controller to be placed in a sub-directory and work with different URL styles.
{zone-data}

{zone-data:references}
* [Akra's DevNotes Zend Framework: Router Again|http://www.akrabat.com/2006/03/15/zend-framework-router-again/#more-35]
{zone-data}

{zone-data:requirements}
* Front Controller to be placed in a sub-directory
* Allow different URL styles
{zone-data}

{zone-data:dependencies}
{zone-data}

{zone-data:operation}
This change inspects the URL and removes the base part of the URL to provide a clean PATH_INFO portion to the Router/RewriteRouter. The change is the same for either Router class.

{zone-data}

{zone-data:class-list}
{zone-data}

{zone-data:use-cases}
Allows URLs like the following:

www.mydomain.com/mycontroller/myaction/
www.mydomain.com/index.php/mycontroller/myaction/
www.mydomain.com/sub/dir/mycontroller/myaction/
www.mydomain.com/sub/dir/index.php/mycontroller/myaction/

An enhancements would be to allow routing based on parameters as well, such as:

index.php?controller=mycontroller&action=myaction
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Controller_Router
{
private $script_extension;

public function __construct($script_extension='.php')
{
$this->script_extension = $script_extension;
}

public function route(Zend_Controller_Dispatcher_Interface $dispatcher)
{
/**
* @todo Replace with Zend_Request object
*/
$path = $_SERVER['REQUEST_URI'];
if (stripos($path, $this->script_extension) !== FALSE) {
$base = $_SERVER['SCRIPT_NAME']; // using script name
} else {
$base = dirname($_SERVER['SCRIPT_NAME']); // using rewrite rules
}
$path = substr($path, strlen($base));
if (strstr($path, '?')) {
$path = substr($path, 0, strpos($path, '?'));
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>