php - Calling custom plugin from view helper -
is there way call custom plugin view helper in zf3?
as per zf3, factory helper created me.
in zf2 how call plugin.
$ecommerceplugin = $this->getservicelocator() ->get('controllerpluginmanager') ->get('customplugin');
as servicelocator removed zf3, how call plugin?
edit module.config
'view_helpers' => array( 'invokables' => array( 'customplugin' => \mymethod\controller\plugin\customplugin::class ) ),
mymethodcontroller\customplugin
class customplugin extends abstractplugin { //my methods }
i recommend registering customplugin
viewhelpermanager
. can find information configuration in zend's manual. typically how module's module.config.php
may look:
<?php return [ 'controller_plugins' => [ 'invokables' => [ 'customplugin' => \mymethod\controller\plugin\customplugin::class ], ], ];
to register use view helper add:
<?php return [ 'controller_plugins' => [ 'invokables' => [ 'customplugin' => \mymethod\controller\plugin\customplugin::class ], ], 'view_helpers' => [ 'invokables' => [ 'customplugin' => \mymethod\controller\plugin\customplugin::class ] ], ];
this new config allow call $this->customplugin()
both controllers , views. now, may run situation in need inject dependencies plugin/view helper. in case can create factory class handle finding , injecting dependencies , change config to:
<?php return [ 'controller_plugins' => [ 'factories' => [ 'customplugin' => \mymethod\controller\plugin\customplugin::class ], ], 'view_helpers' => [ 'factories' => [ 'customplugin' => \mymethod\controller\plugin\customplugin::class ] ], ];
now when plugin/view helper called, factory run , assemble desired class. let me know if have questions. there lot of flexibility in config , specific requirements or example of customplugin
class , module.php
/module.config.php
config provide more accurate example of looking for.
Comments
Post a Comment