Useful libraries

SyDES out of the box has several useful libraries. You can also use another libraries that are loaded by autoloader, if placed in a folder /vendor.

Cache - Caching in files

$this->cache->get($key) Gets an array by unique key
$this->cache->set($key, $value[, $expire = false]) Stores an array with a specific key. You can specify the expiration time in seconds other than the default
$this->cache->clear([$key = false]) Clears the cache by the key, or even all, including html-page caches

Config - Keeping and work with any configs

$config->get([$key = '']) Returns data stored under key, or an array of all data
$config->set($data_array) Saves the entire array as a configuration
$config->set($key, $value) Saves data to specified key
$config->delete([$key = false]) Deletes data with the specified key, or even all
$config->save() Saves the current configuration in database

Example

$config = new Config('my_module'); //loads from the database configuration my_module or creates a new, empty
$url = '/some/url';
$config->set('url', $url)
$url2 = $config->get('url');
$config->delete('url')->save();

H - creating forms and html snippets

H::select($name, $value, array $source, $attr = array()) Returns the select tag
H::checkbox($name, $value, array $source, $attr = array()) Returns the checkbox
H::radio($name, $value, array $source, $attr = array()) Returns the radio-button
H::yesNo($name, $status) Returns the radio-button with 2 vsalues, Yes and No
H::string($name, $value, $attr = array()) Returns the string input
H::input($name, $value, $type, $attr = array()) Returns the any type input
H::hidden($name, $value, $attr = array()) Returns the hidden input
H::textarea($name, $value, $attr = array()) Returns the textarea
H::button($label = 'Submit', $type = 'submit', $attr = array()) Returns the any button
H::password($name, $attr = array()) Returns the password input
H::link($title, $href, $attr = array()) Returns the anchor
H::saveButton($file = '', $button = '') Returns the special save-button, in admin center
H::breadcrumb($crumbs) Returns the breadcrumb
H::pagination($url, $total, $current, $limit = 10, $class = 'pagination', $links = 3) Returns the pagination
H::treeList(array $data, closure $callback, $attr = '', $max_level = 20) Returns tree or unordered lists from flat array with any content returned by callback
H::listLinks($data, $current = '', $attr = '') Returns the flat list with links
H::table($rows, $header = array(), $attr = '') Returns the table
H::tab($data, $current = '', $position = 'top', $attr = '') Returns the tabs
H::accordion($data, $current = '') Returns the accordion
H::modal($title, $body = '', $footer = '', $form_url = '') Returns the modal window
H::form($data) Returns the simple flat form, generated from array
H::attr($attr) Returns the attribute string, by array
H::parseAttr($attr_string) Returns aray with parsed attribute string

Loader - loader models, views, and language packs

$this->load->model($module[, $global = true]) Loads a model of the selected module to the variable with name $this->mymodule_model. If you pass false in the second argument, it returns the model.
$this->load->view($template, $data = array()) Returns compiled template with data transmitted by the second argument.
$template must be a string type mymodule/view, where the view - the name of the file in the folder /system/module/mymodule/view/
$this->load->language($filename[, $global = true[, $language = false]]) Loads in the global variable or return translations on the current language or a specific module information block.
$filename should be a string type module_mymodule or iblock_myiblock
The third argument can specify a language for the translation.

Request - All data from the request

$this->request->get['key'] Escaped data from $_GET
$this->request->post['key'] Escaped data from $_POST
$this->request->cookie['key'] Data from $_COOKIE
$this->request->files['key'] Data from $_FILES
$this->request->server['key'] Data from $_SERVER

Response - collector of all data for the server response

$this->response->notify($message[, $status = 'success']) Adds a notice in response with a specific status. After render the page, it will pop up in the upper right corner. It works for the ordinary and AJAX requests
$this->response->alert($message[, $status = 'success']) Adds a alert in response with a specific status. When displaying the page, it appears to before content. It works for the ordinary and AJAX requests
$this->response->addHeader($header) Adds to a response header line
$this->response->addJsL10n($array) Adds an array in response to translation of texts for js. Use function syd.t('word') to translate
$this->response->addJsSettings($array) Adds an array of settings for js into response . Available in a variable syd.settings
$this->response->redirect([$url = '']) Urgent program termination and redirect to the main page or in the specified direction. It works for the ordinary and AJAX requests
$this->response->reload() Reloads page after AJAX request.
$this->response->flush() Urgent program termination, sending response headers and body
$this->response->data An array to store all the data that is required to pass the response. Render takes information from there.
$this->response->style List of style files that you want to add to the page
$this->response->script List of script files that you want to add to the page
$this->response->body Put here complete response body, before calling flush()



If you want to know something further - ask in the comments. The documentation will be complemented by your questions.
© Arthur Grand, 2011–2024
Powered by SyDES