Improved URL rewriting support

When this code was written, it did not include an internal URL mapper
and each page was loaded by a PHP script. The internal URL was a recent,
mostly unfinished addition.

Base URL is now supported:
 * for views, when they implement the BaseURLAware interface (a base
class that does what most views will do with that is provided -
BaseURLAwareView),
 * in the menu,
 * in form actions,
 * in boxes (for buttons, and for the contents if the inner view
implements BaseURLAware).
This commit is contained in:
Emmanuel BENOîT 2012-02-05 17:42:53 +01:00
parent 3b91a6fc8c
commit 29a026e71a
5 changed files with 69 additions and 10 deletions
includes/box

View file

@ -32,11 +32,18 @@ class BoxButton
return $this;
}
public function render( )
public function render( $baseURL )
{
$url = $this->URL;
if ( $url{0} != ':' ) {
if ( $url{0} != '/' ) {
$url = "/$url";
}
$url = $baseURL . $url;
}
return HTML::make( 'a' )
->setAttribute( 'title' , HTML::from( $this->title ) )
->setAttribute( 'href' , $this->URL )
->setAttribute( 'href' , $url )
->setAttribute( 'class' ,
'box-button' . ( ( $this->class === null )
? '' : ( ' ' . $this->class ) ) )
@ -54,8 +61,8 @@ class BoxButton
}
final class View_Box
implements View
class View_Box
extends BaseURLAwareView
{
protected $title;
protected $class;
@ -72,6 +79,15 @@ final class View_Box
}
public function setBaseURL( $baseURL )
{
parent::setBaseURL( $baseURL );
if ( $this->contents instanceof BaseURLAware ) {
$this->contents->setBaseURL( $baseURL );
}
}
public function setClass( $class )
{
$this->class = $class;
@ -110,7 +126,7 @@ final class View_Box
$buttons = HTML::make( 'div' )
->setAttribute( 'class' , 'box-buttons' );
foreach ( $this->buttons as $button ) {
$buttons->appendElement( $button->render( ) );
$buttons->appendElement( $button->render( $this->base ) );
}
$box->appendElement( $buttons );
}