Manual - URL mechanics

The framework is thought to be very flexible and to allow very fast development, so you have several ways to map URLs.

A file in the filesystem

As discussed on getting started section the .htaccess allows you to add files to www/ folder and so they will be served normally, so the first way to add content is simply uploading to the filesystem. For example sitemap.xml can simply be put there on web root

Url mapper

If you don't need multilanguage support for an url, for example, you want to serve /humans.txt the same content for all the languages you can map this url to be addressed by the framework and be fetched from elsewehere in the filesystem.

Edit init/commonrequests.class.php and add those lines to registerURLS method:

Navigation::addURL('humans.txt', '/mnt/elsewhereondisk/humans.txt', Navigation::ACTION_REQUIRE_FILE,
                   ControllerBase::RESPONSE_TEXT, ControllerBase::CACHE_NO_CACHE);

ControllerBase::CACHE_NO_CACHE specifies that headers will be sent so the browser does not cache the result.

You can server binary files, json, etc... just use ControllerBase::RESPONSE_JSON, ControllerBase::RESPONSE_TEXT or ControllerBase::RESPONSE_TEXTHTML

You can specify the file to be fetched from another place with Navigation::ACTION_REQUIRE_FILE, but you can specify a function to be executed, for example:

Navigation::addURL('humans.txt', 'send_humans_file', Navigation::ACTION_CALL_FUNCTION,
                   ControllerBase::RESPONSE_TEXT, ControllerBase::CACHE_NO_CACHE);

So in that last case "send_humans_file()" will be invoked when humans.txt file is requested.

If curl is active Navigation::ACTION_REQUIRE_URL can be specified so the Framework will get the url specified in the second parameter.

MVC /controller/action and params structure

As said the Catalonia Framework aims to help to develop very fast, so a default system to load controllers easily is provided.

If you have a controller called Forums and an Action called actionListForums (the preceding action word in actionListForums is required) you can call invoke it with:

That simple.

If you call then Forums::indexAction will be tried to load. It is expected that you provide an indexAction method for all your controllers

If you call:

Or if you operate in non multi-language Catalonia Framework mode:

Then Forums::listForums will be called and provided with $st_params that is an array like:

Array( 0 => 'order',
       1 => 'asc',
       2 => 'newer_than',
       3 => '2013')

To make even easier dealing with parameters another array will be provided to the controller, that is $st_params_url that is an array in pairs like:

Array( 'order' => 'asc',
        'newer_than' => '2013);

Please note that all the Controller Names are sanitized with the regular expression in Strings::getSanitizedControllerName($s_name):

$s_sanitized= preg_replace('/([^a-z0-9])/', '', $s_name);

Array injections in the params are also removed, so only strings will be passed to the controller

So an usual Controller's Action is like:

public function actionIndex($s_url = '', $st_params = Array(), $st_params_url = Array(), $o_db = null) {

If the controller does not exists an Exception will be thrown and captured in index.php and an error page will be shown.
A default view views/errors/errorgeneric.php is provided, and all the errors can be customized.

Section definer

The framework provides an additional way to deal with Urls. Normally all the webs have sections, and they need to be called from other places in the web. And is easy to break those links with a rename of the page (may be for SEO reasons).

To solve that problem the Frameworks offers the Section mechanism. Through the Section class you can register a section, and you can request the url for that section later, and you will get it independently of the language of the user.

This is done in commonrequests.class.php in the method:

public static function registerSections($o_db = null) {

So there, to define a section manual, that has the same URL for all the languages in your site you will go:

Section::registerSection('manual', $s_prefix.'manual', 'Manual', 'Index');

So you will define a Section identified by 'manual', that will reply to /[LANG]/manual or /manual depending on if multi-languge is enabled and will call the Class Manual and Method Index (actionIndex)

If you want to use different SEO URLS for the different languages for the section download you will go like:

Section::registerSection('download', $s_prefix.t('seo_url_download'), 'Download', 'Index');

In the folder translations/ you have the localization files and a key 'seo_url_download' in each of them with the value for that language.

Sections can also be attached to Menu objects to create menus, like in the DemoApp.

Back to Main Manual page