Your First App
First steps
Now that we are all set up lets start building our first Enbici application. First we should start by giving a name to our application. Inside our views folder in the layouts there is the master layout open it and give your application a default name for when users are first starting the app.
{$title|default:"Enbici app"}
You can change the name of you application in the master layout or in the ApplicationController.
class ApplicationController extends EnbiciController {
public function init(){
$this->view->assign('title', 'Enbici app');
}
}
Both of this provide the same result but one uses the $title variable inside the master layout and the other uses the default value for setting up the name of our application.
What we see in ApplicationController is the method for initializing our application. Any default settings or things we want to run before anything else in our application should go inside our ApplicationController init method, so that is where we can put the name for our application. If we later want to change the name of our application we can do that using the same assign method.
Every controller in the application shares the same view so we could assign something to our view and change it would be replaced if another controller changes it later on.
Adding actions
Now lets add an action to our IndexController
class IndexController extends ApplicationController
{
public function addAction($value1, $value2 = 2){
$this->view->assign('title', 'Adding action');
$this->view->assign('value1', $value1);
$this->view->assign('value2', $value2);
$this->view->assign('result', (int)$value1 + (int)$value2);
}
}
Add a view to the Index folder named "add.tpl with the following
Add
{$value1} + {$value2} = {$result}
Now you have your own adding action that you can call by directing your browser to "yourappurl.com/index/add/1/2" or "yourappurl.com/add/1" (both do the same). If you try to send no parameters you will get an error since at least one parameter is needed, and if you send too many parameters you will also get an error since you are trying to send more parameters to the action than the ones permitted.
The routing functionality is made available by Enbici with a little help of the .htaccess file that should be located in the root of your project.
blog comments powered by Disqus