init()
public function init() { //...your PHP code...// return true; }
Provides you with a chance to run Plugin code before the page is displayed and allows you to change how your Plugin will be displayed.
In your pluggable modules, from Zenario 7.0 onwards.
The init()
method has been created for you to run pre-display code.
It is called by the CMS before any output has been sent to the client. As such, you should not use it to display any output yourself.
Instead you are encouraged to use it to initialize any variables your Plugin has, and handle any form submissions that your Plugin accepts.
The init()
method also gives you the chance to change how your Plugin will be displayed by the CMS, by calling the initialization functions.
Your init()
function should return either true or false when the CMS calls it. This return value determines whether the Plugin will be displayed.
Be aware that logged-in Admins will always see your Plugin, even if you return false with your init()
function. If this is not what you intended, you will need to repeat the check in your showSlot()
function for Admins.
public function init() { if ($this->hypotheticalMethodThatCountsThings() == 0) { return false; } if ($this->post('submit')) { $this->hypotheticalMethodThatHandlesFormSubmission(); } return true; }
Here, the example Plugin is hidden to visitors if its hypotheticalMethodThatCountsThings()
returns 0. In addition, it if it detects a form submission then hypotheticalMethodThatHandlesFormSubmission()
is called.