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:
parent
3b91a6fc8c
commit
29a026e71a
5 changed files with 69 additions and 10 deletions
includes/core
|
@ -49,6 +49,9 @@ abstract class Page
|
|||
}
|
||||
}
|
||||
} elseif ( ! is_null( $rc ) ) {
|
||||
if ( $rc{0} != '/' ) {
|
||||
$rc = $this->baseURL . '/' . $rc;
|
||||
}
|
||||
header( "Location: $rc" );
|
||||
$rv = true;
|
||||
}
|
||||
|
@ -121,7 +124,7 @@ abstract class HTMLPage
|
|||
foreach ( $menu as $link => $title ) {
|
||||
$html->appendElement( HTML::make( 'li' )
|
||||
->appendElement( HTML::make( 'a' )
|
||||
->setAttribute( 'href' , $link )
|
||||
->setAttribute( 'href' , $this->getBaseURL() . '/' . $link )
|
||||
->setAttribute( 'title' , HTML::from( $title ) )
|
||||
->appendText( $title ) ) );
|
||||
}
|
||||
|
@ -170,6 +173,9 @@ abstract class HTMLPage
|
|||
}
|
||||
|
||||
foreach ( $this->views as $view ) {
|
||||
if ( $view instanceof BaseURLAware ) {
|
||||
$view->setBaseURL( $this->getBaseURL( ) );
|
||||
}
|
||||
$container->append( $view->render( ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,29 @@ interface View
|
|||
public function render( );
|
||||
}
|
||||
|
||||
interface BaseURLAware
|
||||
{
|
||||
public function setBaseURL( $baseURL );
|
||||
}
|
||||
|
||||
abstract class BaseURLAwareView
|
||||
implements View , BaseURLAware
|
||||
{
|
||||
protected $base;
|
||||
|
||||
public function setBaseURL( $baseURL )
|
||||
{
|
||||
$this->base = $baseURL;
|
||||
}
|
||||
}
|
||||
|
||||
interface TitleProvider
|
||||
{
|
||||
|
||||
public function getTitle( );
|
||||
|
||||
}
|
||||
|
||||
|
||||
final class HTML
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue