Skip to content

Latest commit

 

History

History
304 lines (164 loc) · 7.57 KB

api-gila.rst

File metadata and controls

304 lines (164 loc) · 7.57 KB

Class gila

Common methods for Gila CMS

controller($c, $file, $name=null)

(static) Register a new controller.

param string $c

Controllers name

param string $file

Controller's filepath without the php extension

param string $name

Optional. Controller's class name, $c is used by default

Example:

gila::controller('my-ctrl', 'my_package/controllers/ctrl','myctrl');

route($r, $fn)

(static) Registers a function call on a specific path.

param string $r

The path

param Function $fn

Callback for the route

Example:

gila::route('some.txt', function(){ echo 'Some text.'; });

onController($c, $fn)

(static) Registers a function to run right after the controller class construction.

param string $c

The controller's class name

param Function $fn

Callback

Example:

gila::route('blog', function(){ blog::ppp = 24; });

action($c, $action, $fn)

(static) Registers a new action or replaces an existing for a controller.

param string $c

The controller's class name

param string $action

The action

param Function $fn

Callback

Example:

gila::action('blog', 'topics', function(){ blog::tagsAction(); });

onAction($c, $action, $fn)

(static) Runs after an action and before the display of view file.

param string $c

The controller's class name

param string $action

The action

param Function $fn

Callback

Example:

gila::onAction('blog', 'topics', function(){ view::set('new_variable', 'value'); });

before($c, $action, $fn)

(static) Registers a function to run before the function of a specific action.

param string $c

The controller's class name

param string $action

The action

param Function $fn

Callback

Example:

gila::action('blog', 'topics', function(){ blog::tagsAction(); });

addLang($path)

(static) Adds language translations from a json file.

param string $path

Path to the folder/prefix of language json files

Example:

gila::addLang('mypackages/lang/');

addList($list, $el)

(static) Adds en element in a global array.

param string $list

Name of the list

param mixed $el

Value

getList($list)

(static) Returns the array of a list.

param string $list

Name of the list

widgets($list)

(static) Register new widgets.

param Array $list

Example:

gila::widgets( [‘wdg’=>’my_package/widgets/wdg’] );

content($key, $path)

(static) Register new content type.

:param String $key Name of content type :param String $path Path to the table file

Example:

gila::content( 'mytable', 'package_name/content/mytable.php' );

contentInit($key, $init)

(static) Make changes on an existing content type.

param String $key

Name of content type

param Function $init

Function to run when initializes the content type object

Example:

gila::contentInit( 'mytable', function(&$table){
    // unlist a column from content administration
    &$table['fields']['column1']['list] = false;
} );

packages($list)

(static) Returns an array with the active packages names.

amenu($items)

(static) Add new elements on administration menu.

param Assoc Array $items

menu items

Example:

gila::amenu([
  'item'=>['Item','controller/action','icon'=>'item-icon']
]);

amenu_child($key,$item)

(static) Add a child element on administration menu.

param string $key

Index of the parent item.

param Array $item

Example:

gila::amenu_child('item', ['Child Item','controller/action','icon'=>'item-icon']);

config($key, $value = null)

(static) Sets or gets the value of configuration element.

param string $key

Index of the element.

param * $value

(optional) The value.

returns

The value if parameter $value is not sent.

setConfig($key,$value='')

(static) Sets the value of configuration element.

param string $key

Index of the element.

param * $value

The value to set.

updateConfigFile()

(static) Updates the config.php file.

equal($v1,$v2)

(static) Checks if two values are set and have the same value.

param * $v1

First value.

param * $v2

Second value.

returns

True or false.

hash($pass)

(static) Generates a hash password from a string.

param string $pass

The string to be hashed.

returns

Hashed password.

option($option,$default='')

(static) Gets an option value.

param string $option

Option name.

param string $default

(optional) The value to return if there option has not saved value.

returns

The option value.

setOption($option,$value='')

(static) Sets an option value.

param string $option

Option name.

param string $default

The value to set.

hasPrivilege ($pri)

(static) Checks if logged in user has at least one of the required privileges.

param string/Array $pri

The privilege(s) to check.

returns

True or false.

dir ($path)

(static) Creates the folder if does not exist and return the path.

param string $path

Folder path.

returns

string

make_url($c, $action='', $args=[])

(static) Generates a url.

param string $c

The controller.

param string $action

The action.

param Array $args

The parameters in array.

returns

The full url path to print.

Examples:

$url1 = gila::make_url('blog','post',[1]);`` returns mysite.com/blog/post/1
$url1 = gila::make_url('blog','',['page1']);`` returns mysite.com/blog/page1

mt ($arg)

(static) Returns modification times in seconds.

param string/Array $arg

Names of keys.

returns

string/Array

Example:

gila::mt('my-table')

updateMt ($arg)

(static) Updates modification time in seconds. You can use this function from your model classes. The cm controller runs updateMt() for any content type in update action.

param string/Array $arg

Names of keys.

returns

string/Array

Example:

gila::updateMt('my-table')