New release, version v0.2.0 (Blazed), download from github:
Changelog:
- Added support for Smarty variables
- Added support for default route
How to use Smarty variables
There are 2 kind of Smarty variables in Alexya:
- Global Variables
- Local Variables
Global Variables
A global variable is a Smarty variable that is accessible in all views, for example the default variable URL is accessible in ALL views of the project, you can use like this:
HTML Code:
<!-- File Test.tpl -->
<a href="{$URL}">Home page</a>
HTML Code:
<!-- File Test2.tpl -->
<a href="{$URL}Login">Login</a>
To declare a global variable you must add it to the array "SmartyVariables", the key is the name that will be used in Smarty and the value is the value (logically). To add a global variable you must do this:
PHP Code:
//File index.php
$SmartyVariables["test"] = "Testing global variable";
//Usage example:
/*
<a href="{$URL}">{$test}</a>
*/
Adding global variables inside a function or a class is kinda similar:
PHP Code:
class Test
{
public function addVariable($name, $value)
{
$GLOBALS["SmartyVariables"][$name] = $value;
}
}
function anotherWayToAddVariable($name, $value)
{
global $SmartyVariables;
$SmartyVariables[$name] = $value;
}
Once you've added the variables to the SmartyVariables they can be used in ALL views.
Local variables
A local variable is a variable that can be accessed just in one view.
To add a local variable you must add it to the array SmartyVariables inside the Model class:
PHP Code:
class Model_Test extends Core_Model
{
public function __construct()
{
$this->SmartyVariables["test"] = "Test local variable";
}
}
And that's it, there's no need to make the $SmartyVariables array since is already declared in the base class Core_Model.
Default route
Sometimes you'll need a default action to execute if the Router didn't match any route, if so, you can use the "default" route:
PHP Code:
$Router->add("default", function() {
die("No routes matched the request, please go back and try again!");
});
And that's it, there's nothing else to do, the "default" will be executed only if there's no matching route.
If there's no default route and the route didn't match any route added, Alexya will throw an exception saying so.
See you!