I am using zf2 and I have created a few plugins that I can call from any controller in any plugin (so, no problem with that).
To do so, in the controller where the plugin is, I have added this to the module.config.php
'controler_plugins' => array(
'invokables' => array(
'myplugin' => 'MyModule\Controller\Plugin\MyPlygin'
),
),
So, with that my plugin is accessible from every controller with juste $this->myplugin().
My problem is that I can't call a plugin from a plugin in another module.
Any idea how to do that?
Thanks
Every plugin contains a reference to the controller it was called from, so you should be able to call any registered plugin from within another plugin like so:
$this->getController()->myplugin();
Related
I want to create a routing in Kohana Framework Version 3.3.1.
I want URL like http://www.test.com/male/London and internally they will act like below URL-
http://www.test.com/list/search/London
I want to hide the controller and action name from the URL.
Any help is greatly appreciated.
This can be accomplished by using routes in bootstrap.php and/or a module's init.php file.
For example, you could set up a route for (male/<location>) and then your default controller would be list and the action search.
You could then access the location within the controller/action by using $this->request->param('location'); to be used in whatever DB query you need it.
Confused? Have a read through this section of Kohana Docs and it should all make sense.
You have to do two changes in your file:
Bootstarp file :
Route::set('list', 'male/<id>' )
->defaults(array(
'controller' => 'list',
'action' => 'search',
));`
And second is you can make your link like
href="<?php echo URL::site('male/'.id, TRUE) ?>">
And this route file should above at your default route file.
In my ZF2 app I want to change the Template directory at runtime.
The default path is set in module.config.php:
'template_path_stack' => array(
__DIR__ . '/../view',
),
I would like to change that to the equivalent of
'template_path_stack' => array(
__DIR__ . '/../view-alternate',
),
at runtime, so I can dynamically change the theme of the page based on the user preference which is stored in the DB.
Template name resolving is a heavy process. It is better to provide the template name manually.
I recommend you to use 'template_map' instead of 'template_path_stack'. You can create some kind of naming convention to differentiate between the two themes, it can be a prefix that you can manage dynamically.
There is a tool to transform the stack into a template map: https://github.com/zendframework/zf2/blob/master/bin/templatemap_generator.php
The solution I ended up with is to use https://github.com/ZendExperts/ZeTheme.
Combined with the option too save the theme in the session I was able to change the theme because it's not at runtime. A page reload was necessary.
It's a workaround. Not the answer.
I've followed some answers on here and from what I can find on Google but I'm unable to override the renderOptions and setLabelPosition function in the FormMultiCheckbox helper.
I've created a new FormMultiCheckbox.php and saved it in my Application/Form/View/Helper folder and in this file I've redefined the renderOptions and setLabelPostion functions.
Then in Modue.php I've added the following line to the getViewHelperConfig function:
'invokables' => array(
'formmulticheckbox' => 'Application\Form\View\Helper\FormMultiCheckbox'
),
And in my view I'm adding the input to the screen with the following line:
echo $this->formRadio($about_you_form->get('user_gender'), 'block')
Where block is the new layout for the element I've created.
I'm basically trying to get the element to output the input first and then the label instead of putting everything inside the label tags.
I've tried both answers on this post (How to use a custom form view helper in Zend Framework 2?) but I'm getting the error message:
Zend\Form\View\Helper\FormMultiCheckbox::setLabelPosition expects either Zend\Form\View\Helper\FormMultiCheckbox::LABEL_APPEND or Zend\Form\View\Helper\FormMultiCheckbox::LABEL_PREPEND; received "block"
Which would suggest to me that it is not picking up my new renderOptions or setLabelPosition as the error message has been changed in the latter.
Any help or pointers much appreciated.
Regards,
Sean
Zend\Form\View\Helper\FormRadio extends Zend\Form\View\Helper\FormMultiCheckbox
You providing a custom multicheckbox helper to the view helper manager won't change that.
You'll have to create a custom FormRadio helper and have that extend your custom FormMultCheckbox class, then over-ride the formradio helper in your config, just as you did with formmulticheckbox
I'm using Zend Framework 2 (v2.1.4) and I have a partials template that I want to use in several Modules. According to the documentation I can access partials in other Modules, but
That said, it’s likely a better practice to put re-usable partials in shared view script paths.
This sounds like a good idea, but I can't find any documentation on this "share view script path". Where do I find it, and when I've set it, how do I tell the partial() helper to use them?
In your module.config.php
'view_manager' => array(
'template_path_stack' => array(
'mymodule' => __DIR__ . '/../view',
),
'template_map' => array(
'snippets/mypartial' => __DIR__ . '/../view/snippets/mypartial.phtml',
),
),
And use like that
<?php echo $this->partial("snippets/mypartial"); ?>
I'm using a plugin in a CakePHP app together with some (admin) views in it. The URLs inside the plugin views use a structure like:
$html->url(array('plugin' => 'thePlugin', 'controller' => 'theController', ...));
When using other URLs on the same page (e.g. in the layouts file), CakePHP attaches this plugin parameter to every URL, except the plugin parameter is set to null:
$html->url(array('plugin' => null, 'controller' => 'otherController', ...));
That's the "magic" of CakePHP. Nice!
But is there a way to disable the plugin parameter or set the default value to null unless the parameter is explicit set in $html->url()? It would save a lot of time to not rewrite each URL and add 'plugin' => null to disable this parameter.
Thanks for your hints!
cakephp 1.3 have this problem. you can't set router for each plugin. but in cakephp 2 you can set route for every plugin urls.