Quick links: Content - sections - sub sections
EN FR
Jelix 1.5.7

Section: history

^ Coordinator plugins zendframework »
Switch to language: FR

History is a coordinator plugin, it brings some features related with user browsing history.

Plugin declaration

To activate History plugin, set it with its config file in the [coordplugins] section.


[coordplugins]
history = history.coord.ini.php

If you use several coordinator plugins, the order of the plugins declaration in the config file matters. Hence the first declared plugin has precedence on the others. It means that if this first plugin returns an action, the other ones will not be executed. So you need to choose carefully the order of the plugins declaration according to the priority you wish for every plugin. For example if you consider that the bar plugin cannot be executed as long as the foo plugin does not return any action, then you should declare them this way:


[coordplugins]
foo = foo.plugin.ini.php
bar = 1

Keep that in mind when declaring the History plugin.

Principle

History plugin records couples [actions/parameters]

To have 'myapp~default:index' taken into account and registered by the History plugin, you must ask it specifically with the help of $pluginParams.

By default no record is performed if you don't request it that way.


public $pluginParams = array(
        '*'     => array('history.add'=>false),
        'index' => array('history.add'=>true, 'history.label'=>'Home', 'history.title'=>'Go to Homepage')
);
  history.add (:Bool)

If true allows to add a couple to the history history.label (:String) A name for this couple history.title (:String) A description for this couple

Configuration

Size limit

The size of the History is limited to a certain number of couples (default is 10), this limit is customizable in the plugin parameters.


; taille max. de l'historique
maxsize = 20

Avoid duplicates

By default, History records couples one after another keeping the duplicates. If you wish the duplicates to be deleted from the History, you must set it in the parameters.


; if single = true then each page will be registered only once in history
; the latter will be retained.
single = true

Keep record of reloads

When you execute twice the same couple it is added only once. If you want the reloads to be visible in the History you must modify the 'double' parameter.


; If double = false pages will not appear twice a follow time in history.
double = false

Change attributes of a couple when executing

If you use only $pluginParams to declare the couples, you are soon limited for instance to modify the label according to the parameters.

Example:

We want this couple to have the 'Page Foo' label myapp.com/index.php?var=foo&module=myapp&action=default:index

and this couple to have the 'Page Bar' label myapp.com/index.php?var=bar&module=myapp&action=default:index

If we use the basic declaration


public $pluginParams = array(
        '*'     => array('history.add'=>false),
        'index' => array('history.add'=>true, 'history.label'=>'Page Foo')
);

the two couples will have the same 'Page Foo' label.

To get what we want, we must write:


public $pluginParams = array(
        '*'     => array('history.add'=>false),
        'index' => array('history.add'=>true)
);

function index() {
    $rep = $this->getResponse('html');
    
    if( $this->param('var') !== null ) {
        jApp::coord()->getPlugin('history')->change('label', 'Page '.ucfirst($this->param('var')));
    }
    
    $rep->body->assign('MAIN', $rep->body->fetch('myapp~page'));
    return $rep;
}

Use History to reload the page

One frequent case is: you want to execute an action (after a keystroke for example) and come back to the same page.

To perform this, History plugin provides a simple command.


$history = jApp::coord()->getPlugin('history');
return $history->reload( $this->getResponse('redirect') );

If you would like to reload the page modifying one or two parameters, you have just to do this:


$history = jApp::coord()->getPlugin('history');
$ret = $history->reload( $this->getResponse('redirect') );

$ret->params['foo'] = 'bar';

return $ret;

Use History to come back to previous page

Another frequent case is: get the link to come back to previous page.


$history = jApp::coord()->getPlugin('history');
return $history->back( $this->getResponse('redirect') );

Use History to know how long the internet user has been visiting the site

To get this, you must give parameters to the time and session_time_name variables, so that the entrance time on the site is recorded.


; if time = true a variable record time spent on site
time = true
; the name of this variable
session_time_name = "HISTORYTIME"

Then to catch the time spent on the site, you have just to do


$history = jApp::coord()->getPlugin('history');
$delais = $history->time();