Home - mhmxs/lisaframework GitHub Wiki

Create "Hello world!" in 2 minutes

Before you start to use framework you need to [Installation install] it.

This tutorial show you, how to create a simple page in framework with model view controller paradigm. In the tutorial you can learn basic functionality of the framework, and you get tipps witch classes are important to see them.

Register new url

First step after installation is register new url in config/urls.cfg file, witch is in the config directory. The new enrty need looks like this:

'/helloworld' => array('controller' => 'HelloWorldController','function' => 'showPage'),

The '/helloworld' is the url, and the HelloWorldController is the controller for this page, and the showPage is the function inside the HelloWorldController, witch will run after HelloWorldController's constructor. Function is optional. Other optional parameters:

  • You can use regular expressions in url like
'/helloworld/(foo|bar)/(.*)' => array('controller' => 'HelloWorldController','urlParams' => array("foo_or_bar", "something")),

and you can get this variables from $_GET["something"] and $_GET["foo_or_bar"].

  • You can set parameter and you can use this parameter in Controller
'/helloworld' => array('controller' => 'HelloWorldController','parameter' => 'someParameter'), //in urls.cfg
$this->_parameter //in controller
  • You can set "constant" variables in urls.cfg
'/helloworld' => array('controller' => 'HelloWorldController','params' => array("foo" => "bar")),

and you can get this variables from $_GET["foo"].

Create controller

After you register new url, you need to create the HelloWorldController.php in libraries/Controller directory. The HelloWorldController must extends \Core\Controller\Controller, because basic functionality is implemented in Controller class. You can find system/libraries/Controller/Controller.php class in system/libraries/Controller directory. HelloWorldController looks like this:

namespace Controller;
class HelloWorldController extends \Core\Controller\Controller {
    public function showPage() {
        $this->_view->setLayout("default.html"); //set default layout to view, it means in template you don't need to implement html header, body, and html tags, because they are in layout.
                                                 //Default layout is default.html so this function is optionally

        $this->_view->setTemplate("helloworld.html"); //set template for view to helloworld.html

        $this->_view->setVar("helloWorld", "Hello World!"); //set template variable helloWorld
    }
}

Maybe it is useful if you see system/libraries/View/AView.php class, to understand View funcionality. You can find webroot/templates/layouts/default.html layout in webroot/templates/layouts webroot/templates/layouts directory. If you need to use models in LISA, see ModelInLISA Model in LISA. In this framework there is no rule to name your controllers, models, and templates for view, you need to set these yourself like:

'controller' => 'HelloWorldController' //in urls.cfg
$this->_view->setTemplate("helloworld.html"); //in controller
$model = \Core\Model\Model::init("table_name"); //in controller

Create template

Final step is to create helloworld.html template in webroot/templates directory. The content of the template is this:

{$helloWorld}

Enjoy Hello world

If you check the registered url in your browser, you can get "Hello world!".