Skip to content
LaCodon edited this page Dec 15, 2015 · 2 revisions

This config file is required in order to route every request to a certain Controller, Action and View. It's possible to freely choose a save path for this file but keep in mind, to also adapt the path in the line where it says $famework = new Famework(new Famework_Config('config.ini'), new Famework_Config('routes.ini')); (in /index.php).

Contents


Default routes.ini content:

[default]
famework_route = {root}/:controller/:action
famework_controller = :controller
famework_action = :action

Default section

default.famework_route

required
The path mask for the URL which triggers this Controller.

default.famework_controller

required
The name of the Controller which should get called.

default.famework_action

required
The name of the Action which should get called.

General stuff

{root}

{root} means famework.public_root; e.g.:

  1. Example:
    config.ini

    ...
    [famework]
    public_root = /home/project
    ...

    routes.ini

    ...
    [anything]
    famework_route = {root}/test
    famework_controller = IndexController
    famework_controller = testAction
    ...

    Calling http://www.example.com/home/project/test, will execute IndexController::testAction().

  2. Example:
    config.ini as above and
    routes.ini

    ...
    [anything]
    famework_route = {root}/test/:action
    famework_controller = IndexController
    famework_controller = :action
    ...

    Calling http://www.example.com/home/project/test/home, will execute IndexController::homeAction().

  3. Example:
    config.ini as above and
    routes.ini

    ...
    [default]
    famework_route = {root}/:controller/:action
    famework_controller = :controller
    famework_action = :action
    ...

    Calling http://www.example.com/home/project/login/login.do, will execute LoginController::loginDoAction().

Important: The longer your famework_route, the higher has the whole section to be set in the routes.ini
e.g.: famework_route = {root}/:controller/:action comes before famework_route = {root}

Params in URL

For example, this is useful if you want to extract the language from the URL:

[default]
famework_route = {root}/:lang/:controller/:action
famework_controller = :controller
famework_action = :action

and in your index.php after initializing a new object of Famework (called $famework here):

$lang = $famwork->getRequestParam('lang');
if ($lang === NULL) {
    $lang = 'de';
}
define('APPLICATION_LANG', $lang);

Calling http://www.example.com/en/index/index will execute IndexController::indexAction() and will set APPLICATION_LANG to "en".