Parameters

Every page can receive parameters from the user side/browsers. The CodKep can use 3 type of parameters:

All type of parameters above can access same way in CodKep.

Defining parameters

By security reasons you have to define each parameter before use it. The definition have to specify the type of the parameter which divided to security classes, and can tell other properties.

You can define a parameter with the following function:
par_def($name,$security_class,$source = 'all',$accept_empty = true,$default = NULL,$required = NULL)

Example definition of two get parameter

function mypage()
{
  par_def("id","number0","url",false,NULL,"You have to specify the id of the item");
  par_def("name","text3");
  //...
  //parameters are accesible by par()
  print "Id: ".par("id");
  print "Name:".par("name");
}

Defining in route definition array

It is possible to do the parameter definition in route definition array.

You have to put an associative array under "parameters" index in route definition array. The structure of this array structured this way:

Note: The items of this array are passed to the par_def() function which define the parameters according to this array. Because the values of this array are passed to the par_def() see the documentation of that for further explanations.

An examample defineroute hook which defined two parameter "id" and "name"

function hook_mymodule_defineroute()
{
    $r = [];
    $r[] = [
             'path' => 'showitem/{id}',
             'callback' => 'showitempage',
             'parameters' => [
                                'id' => ['security' => 'number0'
                                         'source' => 'url',
                                         'required' => 'You have to specify the id of the item',
                                        ],
                                'name' => 'text3',
                             ],
           ];
    return $r;
}

function showitempage()
{
    ob_start();
    //You can use par() function here to access parameters
    print "Id:".par("id");
    print "Name:".par("name");
    //...
    return ob_get_clean();
}

Using parameters

par($name, $autodefine_type = 'no')
Returns the value of the parameter $name. The parameter must be defined before the value is requested.

In case the $site_config->parameter_autodefine is set true in site settings the par() function can automatically define the parameter by the security class $autodefine_type.

par_ex($name, $autodefine_type = 'no')
Return true if the parameter is received, otherwise false. It does not raise error if the parameter is not defined.

par_is($name, $value,$autodefine_type = 'no')
Return true if the parameter is received and have same value as $value parameter, otherwise false. It does not raise error if the parameter is not defined.

function mypage()
{
  par_def("id","number0","url",false,NULL,"You have to specify the id of the item");
  par_def("name","text3");

  ob_start();
  if(par_is("id","0"))
  {
    //Only displayed if the "id" parameter is "0"
    print "This is the first element!";
  }

  print "Id: ".par("id");

  if(par_ex("name"))
  {
    //Only displayed if the "name" parameter is received
    print "Name:".par("name");
  }

  return ob_get_clean();
}

Other parameter related functions

par_reset()
Erase all parameter definition.

parameters(array $change = array(), array $infilter = array(), array $outfilter = array())
Returns a key-value array with the defined and set parameters. The parameter name will be the index, the value is the current value of the parameter, except if modified by $change parameter.

Security classes

Every parameter is received through the CodKep parameter system, must meet the restriction of a security class which is assigned to the parameter during the definition. Each security class is defined by a regex. (You can add your own security classes, see below)

Built-in security classes in CodKep:

code nameAllowed characters/contets
bool01onf
number00123456789
number1whitespaces 0123456789 . , -
number1ns0123456789 . , -
numberi0123456789 -
text0whitespaces a-z A-Z 0-9
text1whitespaces a-z A-Z 0-9 - _
text1nsa-z A-Z 0-9 - _
text2whitespaces a-z A-Z 0-9 UnicodeLetters
text2nsa-z A-Z 0-9 UnicodeLetters
text3whitespaces a-z A-Z 0-9 UnicodeLetters - _
text3nsa-z A-Z 0-9 UnicodeLetters - _
text4whitespaces a-z A-Z 0-9 UnicodeLetters - _ . , : ? # / ! ( ) = +
text4nsa-z A-Z 0-9 UnicodeLetters - _ . , : ? # / ! ( ) = +
text5whitespaces a-z A-Z 0-9 UnicodeLetters - _ . , : ? & # / ! ( ) = % + ; @ *
text6whitespaces a-z A-Z 0-9 UnicodeLetters - _ . , : ? & # / ! ( ) = % + ; @ * "
textbase64a-z A-Z 0-9 =
tstwhitespaces a-z A-Z 0-9 UnicodeLetters - : . +
tstnsa-z A-Z 0-9 UnicodeLetters - : . +
isodateNNNN-NN-NN e.g: 2016-10-11
freeno limitations
noonly match to empty string

You can define your own security classes with register_parameter_security_class(name,regex) function.
register_parameter_security_class($name,$regex)

A security class can be defined by a regex. See the following example which define the "user_id" security class in "mymodule" module.

function hook_mymodule_init()
{
    register_parameter_security_class('user_id','/^user_[0-9]+$/');
}

function mypage()
{
  par_def("uid","user_id");
  $uid = par("uid");
  //...
}
Page generated in 0.0536 seconds.