Skip to content
hertsch edited this page Aug 6, 2013 · 2 revisions

It is possible to add one or multiple parameters to the kitCommand. Parameters are used to pass information to the kitCommand.

A parameter can be added by inserting a space, followed by the name of the parameter and then always a opening and a closing squared bracket:

~~ sample parameter[] ~~

You can also add multiple parameters:

~~ sample parameter[] parameter_two[] parameter_three[] ~~

Each Parameter can contain values, which are placed between the square brackets. The values can contain different data and formatted in any way.

~~ sample parameter[Value 1] parameter_two[{15|2|33|"abc"}] ~~

The name of the kitCommand must always placed at the first position, followed by the additional parameters.

  • The name of a parameter is always case insensitive and will be converted to lowercase
  • The sequence of parameters is not important
  • The values of a parameter may be case sensitive

Please try the following kitCommand:

~~ HelloUser ~~

You will be prompted to add a parameter with your name to the kitCommand, for example:

~~ HelloUser name[Eddie] ~~

This will result in

Hello Eddie!

Here is the code of the controller:

$app->post('/command/hellouser', function() use($app) {
    $parameter = $app['request']->request->get('parameter');
    if (isset($parameter['name']) && !empty($parameter['name'])) {
        return sprintf('Hello %s!', $parameter['name']);
    }
    else {
      return 'Please use the parameter "name[]" in the kitCommand to submit your name!';
    }
});

With use($app) you enable the function() within the closure to access the kitFramework application.

$parameter = $app['request']->request->get('parameter');

get all kitCommand parameters into the variable $parameter and with $parameter['name'] you can access the value of the name.

Try the following kitCommand:

~~ HelloInfo ~~

This will prompt something like:

Array
(
    [locale] => de
    [page_id] => 1
    [page_url] => http://localhost/wb283/pages/kitcommand.php
    [user] => Array
        (
            [id] => 23
            [name] => eddie
            [email] => [email protected]
        )    
)

The kitFramework pass always some additional information to the controller. You can access them with:

$cms = $app['request']->request->get('cms');

If the $cms['user']['id'] is greater than -1 the user is authenticated, in this case the name contains the username and the email the email address of the user.

The kitFramework also set a lot of constants you can use.

If you need access to POST parameters (i.e. if you are using a form) use:

$POST = $app['request']->request->get('POST');

and if you need access to GET parameters (from the CMS) use:

$GET = $app['request']->request->get('GET');

In the next step we start using objects for the controllers.

Clone this wiki locally