Always use the CMSimple_XH framework

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Always use the CMSimple_XH framework

Post by cmb » Fri May 02, 2014 8:48 pm

Hello Community,

when developing plugins, I suggest to always use the CMSimple_XH framework, i.e. to make all additional requests through CMSimple_XH's index.php, instead of requesting stand-alone scripts somewhere in the plugin folder.

This has the advantage that you have immediate access to the full CMSimple_XH API in those scripts, and you don't have to pass around some values (e.g. config options, language strings) in the session or GPC parameters, resp. construct them yourself. Even if that is not necessary for you now, it may be necessary in the future. For instance, for CMSimple_XH 1.6 it was scheduled to introduce named sessions to be able to completely insulate multiple XH installations on the same domain--unfortunately we had to delay this improvement because of such external scripts being unable to know the session name, and there seem to be rather many around. However, I still hope we can use named session in the future (currently it's on the 1.7 roadmap, but that's probably to soon).

The only drawback of this approach is the often wasteful computation of unnecessary information (such as reading and parsing the content file). However, this is already a problem for normal page requests, as often many plugins are not involved, but nonetheless processed. I'm sure this could be improved, but the related discussion should happen in another thread.

The general technique to handle such requests is to check for the existance of a certain GET/POST parameter, to send (i.e. echo) the ouput and to exit immediately. An example from Pagemanager 2.0.1 (plugins/pagemanager/classes/Controller.php line 489):

Code: Select all

switch ($action) {
case 'plugin_data':
    $this->model->getHeadings();
    header('Content-Type: application/xml; charset=UTF-8');
    echo $this->pages();
    exit;
Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply