A lightweight annotation based MVC framework
/**
* @Request index
*/
public function run()
{
$this->view->var = $this->request->variable;
}
The request /index is mapped to the run method.
All parameters in the POST or GET will be set in $this->request
.
Setting a variable in $this->view
makes it available to the view.
If no view is specified the framework assumes there is a corresponding file in the view
folder.
In this instance that file would be view/index.html
.
/**
* @Request index
* @Parameter -> ["param1"]
* @Parameter -> ["param2", "\xframe\validator\RegEx('/u[0-9]{3}[a-z]/i')", false, 'u000A']
*/
public function run()
{
echo $this->request->param1;
echo $this->request->param2;
}
Using the @Parameter
annotation will map parameters in the request URI to the $this->request
object.
For example, with the URI /index/value1/u123Z
the above code would output “value1” and “u123Z”.
As seen in the above example, there are several validation settings you can include for a parameter.
/**
* @Request index
* @Template default
*/
public function run()
{
}
You can override the default view template using the @Template
annotation.
In the example above instead of looking for view/index.twig
the framework will use view/default.twig
.
/**
* @Request index
* @CacheLength 3600
*/
public function run()
{
}
If the CACHE_ENABLED
option is set to true and @CacheLength
has been set the framework will store the result of the request in memcached and return it for subsequent requests.
/**
* @Request index
* @Prefilter Xframe\Request\Prefilter\ForceHTTPS
*/
public function run()
{
}
If the @Prefilter
annotation is present and the value is object that implements the Prefilter
interface the framework will call the run()
method of the object before the request is processed.
/**
* @Request index
* @Prefilter Xframe\Authentication\AuthenticationPrefilter
* @CustomParam -> ["level", "Administrator"]
* @CustomParam -> ["userType", "Customer"]
*/
public function run()
{
$this->request->level; // === 'Administrator'
}
You can define hard coded parameters using @CustomParam
/**
* @Request index
* @View Xframe\View\Json
*/
public function run()
{
}
The DEFAULT_VIEW
option set in the ini file can be overridden using the @View
annotation.