Шпаргалка MODx API

 

MODx configuration

$site_name=$modx->config['site_name'];
$site_url=$modx->config['site_url'];
$site_start=$modx->config['site_start'];
$error_page=$modx->config['error_page'];
$base_path=$modx->config['base_path'];
$base_url=$modx->config['base_url'];
$rb_base_dir=$modx->config['rb_base_dir'];
$rb_base_url=$modx->config['rb_base_url'];
$modx_charset=$modx->config['modx_charset'];

Page information

$parentid = $modx->documentObject['parent'];
$pageid = $modx->documentObject['id'];

Don't use the following if you want to use php switch and want to parse a modx function inside.

$id=$document['id'];
$pagetitle=$document['pagetitle'];
$longtitle=$document['longtitle'];
$description=$document['description'];
$alias=$document['alias'];

$anotherpage = $modx->getDocument(127, '*', 1); // 127 is the page id, 1 is published
$anotherpage['content']; //shows the content

Sessions/User information

$username = $modx->getLoginUserName();
$fullname = $_SESSION['webFullname'];

Snippets

$params['test']=1;
$params['dummy']=2;
$snippet=$modx->runSnippet('snippet_name', $params);

Chunks

$chunk=$modx->getChunk('chunk_name');

$params['test']=1;
$params['dummy']=2;
$chunk=$modx->parseChunk('chunk_name', $params, '');

Template variables Updated for Revolution

//@SELECT
@SELECT pagetitle FROM modx_site_content WHERE parent = 329 ORDER BY pagetitle

$tv = $modx->getTemplateVar('vouchers', "",$row['id']);
echo $tv['value'];

$document_tvs=$modx->getTemplateVarOutput(true, $id);
$templatevar_output=$document_tvs['template_variable_name'];

Placeholders

$var=$modx->getPlaceholder('placeholder_name');
$modx->setPlaceholder('placeholder_name', $var);

Other functions

$url = $modx->makeUrl(25); // 25 being the page to go to
$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', '301');

$tblsc = $modx->getFullTableName('site_content');

// Get MODx documents
$id=$modx->documentIdentifier;
$document=$modx->getParent($id);
$document=$modx->getDocument($id);
$document=$modx->getDocumentChildren($id);
$document=$modx->getActiveChildren($id, 'menuindex', 'ASC');

// Make URL
$url=$modx->makeUrl(intval($id));

// Make URL in HTML
?>
[~id~]

// Send Redirect to the Browser
$count_attempts=1;
$modx->sendRedirect('http://www.newdomain.com', $count_attempts, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');

// Forward to a new MODx document without reloading the page
$modx->sendForward($id);

// Get MODx configuration in HTML
?>
Omegicus LLC
https://omegicus.org/

// Handle MODx events
$event=$modx->Event;
switch($event->name)
{
case "OnBeforeDocFormSave":

break;
}

Отправить заявку на создание сайта

Сообщение отправлено