Notes for the programmer about the new possibilities of MODx Revolution

In this article I want to consider some new possibilities of MODx Revolution, which was not in the younger branch of MODx Evolution. With this CMF I started working when I was available version modx-2.0.0-beta-2, i.e. about half a year ago. I can say that for the period since the summer of 2009 when the system was only in beta stage, before release in the summer of 2010, MODx has come a long way in its development, adding new features, is faster and better to work with the old functionality. I believe that currently MODx Revolution is really powerful platform for building a variety of web applications from simple websites to large portals. So, let's begin.

I will try to describe the next innovation MODx Revolution:
    the
  1. xPDO
  2. the
  3. namespaces
  4. the
  5. Contexts
  6. the
  7. caching system
  8. the
  9. Internationalization

Now everything in order.


xPDO

First extract from the xPDO official website:

xPDO – ORB is a lightweight library that works on PHP 4 and 5, providing the benefits of the new standard to access databases in PHP 5.1 or above – PDO. It implements a very simple but effective Active Record pattern for data access.

xPDO – MODx is a community-developed ORB-library, which is based the whole system work, even the main class MODx inherits from a class xPDO. In MODx Revolution all the database actions are performed using xPDO, component developers are also encouraged to use this library, however, the old mechanism of work with the database from MODx Evolution are still there for backward compatibility.
xPDO provides a single interface for connection with various types of databases. Currently available connectors for MySQL and SQLite in the future, we will expand our list of supported databases.
All data manipulations are performed using specialized methods. To select, create, update, and deletion of data does not require the use of direct requests, making virtually eliminated SQL injection.

The following example selects from the database all resources in the context of the web, which have parent resource set to 3 and prints out their titles.

//select resources for a given condition
$resources = $modx->getCollection(“modResource”, array(
“parent” => 3,
“context_key” = > “web”
));
//pass on the received array and print the title of the resource
foreach ($resources as $resource) {
echo($resource- > get(“pagetitle”).”|”);
}


In a similar way performed create, edit and delete items:

//create new object
$resource = $modx- > newObject(“modResource”);
//set the title and content of the page
$resource->set(“pagetitle”, “My title”);
$resource- > set(“content”, “My content”);
//and save it to database.
//Note! Prior to calling this method the data in the database will not be written!
$resource->save();

//get the resource with ID 1
$resource = $modx- > getObject(“modResource”, 1);
//set the new title
$resource->set(“pagetitle”, “New title”);
//and save the changes
$resource->save();

//get the resource ID 5
$resource = $modx- > getObject(“modResource”, 5);
//remove
$resource->remove();


namespaces

Namespaces are used to identify various components that are not included in the core of the system. In fact, the namespace is the folder in core/components containing the model files for xPDO, dictionaries and other necessary components resources.
Namespaces are used when you create additional pages and menu items in system administration.
Each external component must have its own namespace which can be created in system administration.

Contexts

The context of storage resources in MODx. Each resource must be one of the contexts. The context has a private cache of the resource tree belonging to him. Accordingly, each time you add or remove a resource from the context, the system clears the cache. At the repeated reference to the context is generated and the entry in the cache of the resource tree, which may cause some slowing of the site with frequent adding or removing resources. Therefore, having a frequently updated site with lots of documents, it may be prudent to make some sections into separate contexts.
Access policy contexts are implemented using the set of rights that are established for a specific group of users within a context. Therefore, it is possible to prohibit specific users to edit or even view resources in a particular context.
By default, after installation there are 2 context: web (context of the user of the website) and mgr (the context of the administrative panel).

In the context of the web anonymous users have view-only rights, resources, and users belonging to the Administrator group have full rights to all actions with resources. Accordingly, in the context of the mgr only users in the Administrator group can perform any actions with the resources.
Contexts can be used to create multiple sites on a single installation MODx Revolution, and also to create subdomains in which site users can post their materials. However, to implement such behavior will require a small edit of the file index.php because it default initializes the web context, and we need in some cases to initialize other contexts.

caching system

MODx Revolution provides a new caching system, which the programmer can store in the cache any data and fully manage their life cycle. Sample entry and data retrieval from the cache (taken from official documentation MODx):

// write something to the cache
$colors = array('red','blue','green');
$modx- > cacheManager- > set('colors',$colors); /* written in core/cache/colors.cache.php */

// now get written data
$colors = $modx- > cacheManager- > get('colors');
foreach ($colors as $color) {
echo $color.'-';
} /* displays 'red-blue-green' */


Also the stored data can be deleted. Example of deleting:


$modx- > cacheManager- > delete('colors');


Internationalization

MODx Revolution allows you to create internationalized version of the site using the dictionaries are stored in files or database. Dictionaries are divided into the following levels: languages, themes, and strings. In the file system languages are folders that contain the theme files which in turn contain strings.

Consider the example of a storage system MODx dictionaries in the file system.
The root folder of dictionaries contains subfolders with names that match the locales accepted by the IANA (for example, en or ru). Further, each of the language subfolders contains files with names in the format imatinib. And every the theme file contains a string in the format

$_lang['identificators'] = 'znacheniyami';

On the page the string value from the dictionary inserts the following tag:

[[%identificationi? &topic=`imately` &namespace=`modx` &language=`language`]]

The namespace parameter is used to specify the namespace for which to load the vocabulary. The language parameter is optional, in its absence, will get the language set in the system settings by default.

I tried to consider only some new possibilities of MODx Revolution. This system is fraught with much more than I now can imagine. I'm happy to continue to explore this wonderful, in my opinion, CMF, and it has not disappointed.

Resources

    the
  1. the MODx Official website
  2. the
  3. MODx Documentation
  4. the
  5. xPDO
  6. the
  7. MODx Russia
  8. the
  9. Unofficial Russian-speaking community of MODx
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Briefly on how to make your Qt geoservice plugin

Database replication PostgreSQL-based SymmetricDS

Yandex.Widget + adjustIFrameHeight + MooTools