- Posts: 32
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to load helper from plugin in custom controller
- jackrabbithanna
-
Topic Author
- Offline
- Junior Member
-
Less
More
2 years 3 months ago #209415
by jackrabbithanna
I'm working on upgrading an old Limesurvey 2.x with lots of customs to 3.x or 4.x
The instance has some custom controllers, which load some custom helpers.
I want to move the helper out into a Limesurvey plugin (and controllers too but ..)
So it looks like helper was loaded like this:
Yii::import('application.helpers.customdir.SomeHelperObject');
Where SomeHelperObject.php is in ./survey/application/helpers/customdir
Is there an standard way to load helpers from a LS Plugin?
Can helpers from plugins be loaded from controllers?
The instance has some custom controllers, which load some custom helpers.
I want to move the helper out into a Limesurvey plugin (and controllers too but ..)
So it looks like helper was loaded like this:
Yii::import('application.helpers.customdir.SomeHelperObject');
Where SomeHelperObject.php is in ./survey/application/helpers/customdir
Is there an standard way to load helpers from a LS Plugin?
Can helpers from plugins be loaded from controllers?
The topic has been locked.
- DenisChenu
-
- Offline
- LimeSurvey Community Team
-
Less
More
- Posts: 12895
- Thank you received: 2371
2 years 3 months ago #209422
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic How to load helper from plugin in custom controller
There are no standard way
But check Yii alias :
gitlab.com/SondagesPro/coreAndTools/limeMpdf#basic-usage
Alias is added here : gitlab.com/SondagesPro/coreAndTools/lime...ter/limeMpdf.php#L32
With plugin : i don't know how you construct controller, not real controller.
For administration : see github.com/LimeSurvey/LimeSurvey/blob/5c...PluginHelper.php#L21
But check Yii alias :
gitlab.com/SondagesPro/coreAndTools/limeMpdf#basic-usage
Alias is added here : gitlab.com/SondagesPro/coreAndTools/lime...ter/limeMpdf.php#L32
With plugin : i don't know how you construct controller, not real controller.
For administration : see github.com/LimeSurvey/LimeSurvey/blob/5c...PluginHelper.php#L21
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- jackrabbithanna
-
Topic Author
- Offline
- Junior Member
-
Less
More
- Posts: 32
- Thank you received: 3
2 years 3 months ago #209426
by jackrabbithanna
Replied by jackrabbithanna on topic How to load helper from plugin in custom controller
This is good .. I had a plugin, but didn't have that one line in the init() of the plugin php script
Yii::setPathOfAlias
So I have a basic plugin like so:
class lfSurveyVersions extends PluginBase
{
static protected $name = 'lfSurveyVersions';
static protected $description = 'Customs for Survey Versions functionality';
protected $storage = 'DbStorage';
public function init() {
Yii::setPathOfAlias(get_class($this), dirname(__FILE__));
}
}
Then inside the plugin directory, a helpers directory, and a name space like:
namespace lfSurveyVersions\helpers;
Something for tests I had a simple object
class TempHelper {
static public function someFunction() {
return 25;
}
}
Now enable plugin
Then in my controller .. am able to use like so:
$value = \lfSurveyVersions\helpers\TempHelper::someFunction();
And that works .. Thanks for the help!
Yii::setPathOfAlias
So I have a basic plugin like so:
class lfSurveyVersions extends PluginBase
{
static protected $name = 'lfSurveyVersions';
static protected $description = 'Customs for Survey Versions functionality';
protected $storage = 'DbStorage';
public function init() {
Yii::setPathOfAlias(get_class($this), dirname(__FILE__));
}
}
Then inside the plugin directory, a helpers directory, and a name space like:
namespace lfSurveyVersions\helpers;
Something for tests I had a simple object
class TempHelper {
static public function someFunction() {
return 25;
}
}
Now enable plugin
Then in my controller .. am able to use like so:
$value = \lfSurveyVersions\helpers\TempHelper::someFunction();
And that works .. Thanks for the help!
The following user(s) said Thank You: DenisChenu
The topic has been locked.