Modxhelpers
Library of the helpfull functions for MODX as composer package
Install / Use
/learn @sergant210/ModxhelpersREADME
MODX Helpers
Functions-helpers for MODX. It's made as composer package. Depricated. See modHelpers.
Installation
- Create a plugin which loads composer files.
switch ($modx->event->name) {
case 'OnMODXInit':
$file = MODX_CORE_PATH . 'vendor/autoload.php';
if (file_exists($file)) {
require_once $file;
}
break;
}
- Put the composer.json to the core folder
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/sergant210/modxhelpers"
}
],
"minimum-stability": "dev",
"require": {
"sergant210/modxhelpers": "1.*"
}
}
- Use a terminal tool and run
composer installorphp composer.phar installwithin the folder core.
That's all. Now you can use the functions.
Examples
Check the user exists
if (user_exists(['email'=>'admin@mail.com']) {
// Exists
}
Get the data from the cache
$value = cache('key', 'my_data');
// Or
$value = cache()->get('key', 'my_data');
Send an email
email('pussycat@mail.ru', 'Subject','Email content');
// To the user
email_user('admin', $subject, $content);
Redirect
redirect($url);
//To the resource with the id = 5
redirect(5);
The latest resource
$resourceObject = resource()->last(); // Resource object
$resourceArray = resource()->last()->toArray(); // Resource data as array
The last 10 resources
$resObjects = resources()->last(10);
Array of the resource pagetitles of the parent with the id = 20.
$titles= resources()->where(['parent'=>20])->get('pagetitle'); // array('pagetitle 1', 'pagetitle 2', 'pagetitle 3')
Set a value to the session
session('key1.key2', 'value'); // => $_SESSION['key1']['key2'] = $value;
Get the value from session
$value = session('key1.key2'); // $value = $_SESSION['key1']['key2']
Validates the email
if (is_email($_POST['email'])) {
// Valid
}
Remove child resources of the one with the id = 10
resources()->where(['parent'=>10])->remove();
Count blocked users
$count = users()->profile()->where(['Profile.blocked'=>1])->count();
Load script with the async attribute
script('/path/to/script.js', 'async'); // <script async type="text/javascript" src="/path/to/script.js"></script>
Get an array of users
// Can use the prepared query
$userArray = query('select * from ' . table_name('modUser'). ' WHERE id < ?')->execute(( (int) $_POST['user_id']);
Log error to the error log
log_error($array); // Convert the array to string using print_r().
log_error($message, 'HTML'); // Show message on the page.
Get the list of the pagetitles
return resources()->where(['id:IN'=>children(5)])->each(function($resource, $idx){ return "<li>{$idx}. ".$resource['pagetitle']."</li>";});
Get all users which are members of the "Manager" group
$usersArray = users()->members('Managers')->toArray();
# Get all users from "ContentManagers" and "SaleManagers" groups
$users = users()->members('%Managers')->get();
foreach($users as $user) {
echo $user->username;
}
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
