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

View file

@ -65,9 +65,15 @@ class Ctrl_Form
return $this->form->view( );
}
if ( $cResult ) {
return $this->form->successURL( );
$url = $this->form->successURL( );
} else {
$url = $this->form->cancelURL( );
}
return $this->form->cancelURL( );
if ( $url{0} != '/' ) {
$url = "/$url";
}
return $page->getBaseURL( ) . $url;
}
}

View file

@ -1,7 +1,7 @@
<?php
class View_Form
implements View
extends BaseURLAwareView
{
protected $form;
@ -161,10 +161,18 @@ class View_Form
$name = $this->form->name();
$prefix = $name . '-';
$action = $this->form->action( );
if ( $action{0} != '?' ) {
if ( $action{0} != '/' ) {
$action = "/$action";
}
$action = $this->base . $action;
}
$form = HTML::make( 'form' )
->setAttribute( 'name' , $name )
->setAttribute( 'id' , $prefix . 'form' )
->setAttribute( 'action' , $this->form->action( ) )
->setAttribute( 'action' , $action )
->setAttribute( 'method' , $this->form->method( ) )
->append( $this->renderHiddenFields( $prefix ) )
->append( $visibleArea = HTML::make( 'dl' ) );