📜 ⬆️ ⬇️

MODx Revolution. Results Part 1

Three and a half months have passed since the release of MODx Revolution. I think no one will argue that version 2.0 was very raw and was not ready for use on real projects. I saw a lot of criticism and skepticism on the Russian-language sites about MODx. Something is well deserved, but something is due to the lack of detailed documentation. Currently version 2.0.4-pl2 is available , according to which, in my opinion, it is already possible to summarize: Did the developers choose the right direction and development tools and should we abandon MODx Evolution (1.x) and switch to Revo? In this article I will try to tell you in detail about the main features of the new system, which I only discover for myself.



What is MODx Revolution


')
As the developers say , first of all MODx Revolution is CMF, i.e. a tool for creating web applications, and the CMS that comes bundled is just an appendix. Revo is written in PHP and uses:


Control system





Despite the foregoing, the developers have paid much attention to CMS. It is felt that the convenience of the control system is thought out very carefully.


If you right-click on a section in the resource tree (documents) on the left and select “Quickly create” -> “Document”, a window will open to create a document without reloading the page, which is very convenient. There is also a quick edit (“Quickly update resource”). In the same way, you can quickly create or edit “additional fields”, etc. Documents can be sorted and shifted by section by dragging and dropping in the tree.

However, not everything is so rosy. Because of the heap of “javascript beauties”, the admin works much slower than in Evolution, sometimes it hangs on some actions. Although I think with time this will get better (I did not notice the critical glitches).

Development under MODx Revolution



Separation of user rights. In Evo, the rights were fixed and only in the admin panel (for “managers”). Revo has the opportunity to create its own rights and assign them to individual groups of users. This is done very simply:
Go to “Security” -> “User Groups” -> “Access Policies”. Select the name of the access policy (for example, “Administrator”) and add a “new permission” in editing, for example, “test_action”.
Save and click "Exit". To update the rights, you need to re-enter the system (update session). Now it is possible to check whether the current user has the “test_action” action right anywhere in the component code (snippet, plug-in):

if (!$modx->hasPermission('test_action')){ //     ,   " " return $modx->error->failure($modx->lexicon('access_denied')); } 


This is very short, it is possible to adjust permissions more subtly. In Revo, there is no separation between “managers” and “web users” as in Evo. Access control in the administrative part is defined by the context “mgr”, and in the external part of the site - by the context “web”.

Creating snippets and plugins without any special changes. Most of the function names and arguments from the Evo are saved. To create “packages” (packages) there is a very convenient and easy-to-use PackMan module:

Select snippets, plug-ins, chunks, press the “Export Transport Package” button and get the package archive ready for installation. Now it will be possible to put it in the core / packages / folder and install it through “Package Management”.

Creating pages in the "manager". Now there is no concept "Module". There is a common name "Component". In the management system, you can create a component administration user interface . I will describe briefly the main steps:
1. Create a namespace for our component (“System” -> “Namespaces”).

At the specified path, the “manager” will search for the “controller” of the component. If you are familiar with the MVC pattern , then the concept of “controller” is well known to you.
2. Go to “System” -> “Actions”. Clicking on our namespace "myextra", select "Create an action here." In the line "Controller" we write the name of the PHP file of the controller, which lies in the folder specified above. For example, "index" (index.php).
3. Now create an item in the main menu. We right-click on the “Components” item in the “Top Menu” block and select “Create a menu item here.”

4. In more complex applications, it is worthwhile to put all controllers in a separate folder “controllers”. Here is the content of my index.php controller:

 <?php $corePath = MODX_CORE_PATH.'components/myextra/'; $assetsUrl = MODX_BASE_URL.'assets/components/myextra/'; $controllersPath = $corePath.'controllers/'; $connectorUrl = $assetsUrl.'connector.php'; $cssUrl = $assetsUrl.'css/'; $jsUrl = $assetsUrl.'js/'; $output .= '<div><h2> </h2></div>'; $output .= '<div id="myextra-main-div"></div>'; return $output; 


In reality, this is not recommended. You need to create a model, etc. (about this in the next part). You can use the Smarty template engine:

 $title = ' '; //    $modx->smarty->assign('title', $title); //  return $modx->smarty->fetch($corePath.'templates/main.tpl'); 


PHP can be used as a template engine (templates should be placed in a separate file). And you can fully use ExtJS. Here is an example of outputting a table of values ​​(Ext.grid.GridPanel):

core / components / myextra / index.php:

 <?php $corePath = MODX_CORE_PATH.'components/myextra/'; $assetsUrl = MODX_BASE_URL.'assets/components/myextra/'; $controllersPath = $corePath.'controllers/'; $connectorUrl = $assetsUrl.'connector.php'; $cssUrl = $assetsUrl.'css/'; $jsUrl = $assetsUrl.'js/'; //   HEAD $modx->regClientStartupHTMLBlock('<script type="text/javascript"> var myextra = {}; myextra.connector_url = "'.$connectorUrl.'"; </script>'); $modx->regClientStartupScript($jsUrl.'datagrid.js'); //  grid` $output .= '<h2> </h2>'; $output .= '<div id="myextra-main-div"></div>'; return $output; 


assets / components / myextra / js / datagrid.js:

 Ext.onReady(function(){ //   var store = new Ext.data.JsonStore({ url: myextra.connector_url, //   root: 'object.data', //JSON     totalProperty: 'object.total', //    idProperty: 'orderid', remoteSort: false, prettyUrls: false, fields: [ {name: 0}, {name: 1, type: 'int'}, {name: 2, type: 'float'}, {name: 3, type: 'int'} ] }); store.setDefaultSort(3, 'desc'); //   var grid = new Ext.grid.GridPanel({ store: store, columns: [ {header: " 1", width: 100, sortable: true, dataIndex: 0}, {header: " 2", width: 100, sortable: true, dataIndex: 1}, {header: " 3", width: 100, sortable: true, dataIndex: 2}, {header: " 4", width: 100, sortable: true, dataIndex: 3} ], renderTo:'myextra-main-div', //DIV     width:400, autoHeight: true, loadMask: true, bbar: new Ext.PagingToolbar({ pageSize: 5, //   store: store, //  displayInfo: true, displayMsg: ' {0} - {1}  {2}', emptyMsg: "  " }) }); //  store.load({params:{ action: 'mgr/datalist', // ("") start:0, limit:5 } }); }); 


assets / components / myextra / connector.php:

 <?php /** * Myextra Connector * * @package myextra */ require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php'; require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; require_once MODX_CONNECTORS_PATH.'index.php'; /* handle request */ $modx->request->handleRequest(array( 'processors_path' => $modx->getOption( 'core_path' ) . 'components/myextra/processors/', 'location' => '' )); 


core / components / myextra / processors / mgr / datalist.php:

 <?php $start = $scriptProperties['start']; //   $limit = $scriptProperties['limit']; //   $total = 50; $page = $start+1; //  ""  mysql- $limit_on_page = $total-($total-($page*$limit)); $outputArray = array(); for($i=$start*$limit;$i<$limit_on_page;$i++){ $outputArray[] = array(' '.($i+1),2,3,4); } $outputArray = array( 'total'=>$total, 'limit_on_page'=>$limit_on_page, 'data'=>$outputArray ); return $modx->error->success('',$outputArray); 


As a result, we get the following label:


ExtJS is not at all difficult to learn, as I previously thought. The main desire. It really saves a lot of time.

Documentation MODx Revolution is still very poor. Much of the information has to be found in the source. I hope soon this situation will change, perhaps with your help.

The end of the first part.

From this part, I think everyone understands that MODx Revolution is not much more difficult than Evolution in terms of development, and there are more opportunities for the developer.

Source: https://habr.com/ru/post/108154/


All Articles