How To Confirm A Helper Is Loaded?
Permalink
I'd like to do a little more error checking and I want to be sure my helper has successfully loaded before I call any functions in it.
Does concrete5 have a way to do that?
If not, is there any example code of such a check?
Bob
Does concrete5 have a way to do that?
If not, is there any example code of such a check?
Bob
I see.
The reason I started down this track was seeing some code in the Magic Yogurt theme associated with determining whether or not to do magic to an area based on if we are in edit mode or if magic data were not available:
Maybe this code is up to something else.
Bob
The reason I started down this track was seeing some code in the Magic Yogurt theme associated with determining whether or not to do magic to an area based on if we are in edit mode or if magic data were not available:
!$mdsh->confirm_installed()
Maybe this code is up to something else.
Bob
Your interpretation of that code is about correct.
That helper can be added to any package that uses Magic Data.
What it does is to always create the helper, but within the helper to test if the Magic Data package is installed (and keep a note for efficiency).
The helper provides a utility 'confirm_installed()' so that anything using the helper has an easy test to see if Magic Data is available.
Then the main 'fill()' method of the helper has 2 modes
- if Magic Data is installed, process text for tokens
- if Magic Data is not installed, just return the input text
Its not a normal helper, because it allows the package it is in to adapt to whether another package is available or not.
Most helpers will not need any such error proof code.
The 2 Magic Area models then use the helper and provide similar modes of operation (because it is more efficient that way)
That helper can be added to any package that uses Magic Data.
What it does is to always create the helper, but within the helper to test if the Magic Data package is installed (and keep a note for efficiency).
The helper provides a utility 'confirm_installed()' so that anything using the helper has an easy test to see if Magic Data is available.
Then the main 'fill()' method of the helper has 2 modes
- if Magic Data is installed, process text for tokens
- if Magic Data is not installed, just return the input text
Its not a normal helper, because it allows the package it is in to adapt to whether another package is available or not.
Most helpers will not need any such error proof code.
The 2 Magic Area models then use the helper and provide similar modes of operation (because it is more efficient that way)
Will throw a nasty php error if the helper does not get loaded.