Brand New Helper
Permalink 1 user found helpful
I am trying to create a brand new helper (not override an existing one), but am having trouble. I copied the layout of form/page_selector and have tried naming my class Concrete5_Helper_MyHelper, Helper_MyHelper, Site_Helper_MyHelper, and SiteHelperMyHelper, but keep getting errors similar to this one: "failed to open stream: No such file or directory in C:\wamp\www\c5sp\concrete\core\libraries\loader.php on line 293".
I am calling Loader::helper('subdir/myhelper') from a block. My file is located at /helpers/subdir/myhelper.php, but it seems to be looking for it at concrete/helpers/subdir_myhelper.php
What do I do?
I am calling Loader::helper('subdir/myhelper') from a block. My file is located at /helpers/subdir/myhelper.php, but it seems to be looking for it at concrete/helpers/subdir_myhelper.php
What do I do?
Thank you for your answer. I thought I was doing exactly what you said and combining it with what I saw Concrete5 doing in its core, but after experimenting with permutations between what you provided and what I had, I have determined that Concrete5 has the following rules for brand-new custom helpers that MUST be followed:
- Do NOT use underscores in your helper file name or class name
- Do NOT use subdirectories for your helper file; even though the core does, you can't
- Your helper's file name and your call to load the helper MUST be the same (except for the .php extension in the file name)
- Your helper's class name and your call to load the helper MUST be the same, and the class name MUST have the string "Helper" appended to the end.
Example:
I want to call my helper "CoolStuff".
In /helpers/CoolStuff.php I will have:
My call to load my helper must look like this:
The naming conventions/requirements for each component are VERY strict.
- Do NOT use underscores in your helper file name or class name
- Do NOT use subdirectories for your helper file; even though the core does, you can't
- Your helper's file name and your call to load the helper MUST be the same (except for the .php extension in the file name)
- Your helper's class name and your call to load the helper MUST be the same, and the class name MUST have the string "Helper" appended to the end.
Example:
I want to call my helper "CoolStuff".
In /helpers/CoolStuff.php I will have:
My call to load my helper must look like this:
$whateverVarIWant = Loader::helper('CoolStuff');
The naming conventions/requirements for each component are VERY strict.
You should never have uppercase in a c5 file name. So the ultimate part of your current problem should be
The only exception is where 3rd party libraries already use uppercase within their file names (such as Zend)
(EDIT - removed info about longer/paths/within/helpers/directory as there could be an issue with that)
$helper = Loader::helper('cool_stuff');
The only exception is where 3rd party libraries already use uppercase within their file names (such as Zend)
(EDIT - removed info about longer/paths/within/helpers/directory as there could be an issue with that)
I've modified the color helper and created a new helper. I've seemingly installed this via package. How can I call the helper from within another package?
the loader::helper syntax is returning a path error. It's looking in concrete/helpers for my new helper. Within the helper package the helper is located in the /packagename/helpers folder...
the loader::helper syntax is returning a path error. It's looking in concrete/helpers for my new helper. Within the helper package the helper is located in the /packagename/helpers folder...
I am messing about with a colour helper at the moment.
A glitch I found was that Loader::helper could not find anything in subdirectories of my package /helpers dir. As soon as I moved the code up from /heplers/forms/my_new_color.php to /heplers/my_new_color.php, with the appropriate change in the call to Loader::helper, it all worked.
I don't know if this is a bug, or whether there is something about helpers I couldn't get right when naming the files and loading them.
Seems that path resolution for helpers is not as clear as it is for libraries or models.
A glitch I found was that Loader::helper could not find anything in subdirectories of my package /helpers dir. As soon as I moved the code up from /heplers/forms/my_new_color.php to /heplers/my_new_color.php, with the appropriate change in the call to Loader::helper, it all worked.
I don't know if this is a bug, or whether there is something about helpers I couldn't get right when naming the files and loading them.
Seems that path resolution for helpers is not as clear as it is for libraries or models.
Rather than try to install the helper via package, and then try to call it from within a different package, I've moved the helper to within the package that needs it. The issue I'm now running into is:
I'm using
from the block edit in my package, to call the helper.
If the helper is NOT located within the package at /helpers/rgbcolor.php I get this when adding a supercounters block:
Warning: require_once(/packages/enlil_supercounters/helpers/rgbcolor.php): failed to open stream...
if the helper DOES exist in my package at /helpers/rgbcolor.php I get the following when adding a supercounters block:
Warning: require_once(/concrete/helpers/rgbcolor.php): failed to open stream...
Someone, please share in my confusion :)
I'm using
$fhc = Loader::helper('rgbcolor', 'enlil_supercounters');
from the block edit in my package, to call the helper.
If the helper is NOT located within the package at /helpers/rgbcolor.php I get this when adding a supercounters block:
Warning: require_once(/packages/enlil_supercounters/helpers/rgbcolor.php): failed to open stream...
if the helper DOES exist in my package at /helpers/rgbcolor.php I get the following when adding a supercounters block:
Warning: require_once(/concrete/helpers/rgbcolor.php): failed to open stream...
Someone, please share in my confusion :)
create a file name /helpers/my.php and this a sample code for it:
and for using methods of this helper: