0

Some times ago I wrote a component that I find very convenient to use instead of other kind of authorization tools. I have converted it to CakePHP 3 and it still suits perfectly to my needs, but now I need to call one of its functions from a helper, and I can't figure out how to do that. The component name is PermissionsComponent.

Here is a draft of my helper:

namespace App\View\Helper;
use Cake\View\Helper;
use App\Controllers\Component\PermissionsComponent;

class PermissionsHelper extends Helper {
    function check($action, $redirect = false) {
        // how can I call my component's action check($action, $redirect)?
    }
}

How can I call that component's action from a helper?

ToX 82
  • 1,064
  • 12
  • 35
  • You can't, or let's say you shouldn't, components are for controllers, helpers are for views, they shouldn't talk to each other. – ndm Jan 07 '15 at 13:10
  • possible duplicate of [how to use common function in helper and component In Cakephp](http://stackoverflow.com/questions/24261432/how-to-use-common-function-in-helper-and-component-in-cakephp) – ndm Jan 07 '15 at 13:10

1 Answers1

0

You can't. It sounds more like you should use another object that you can use in both the component and the helper.

// In PermissionsComponent
$permissions = new Permissions();
...
$this->_controller->set('_permissions', $permissions);

And then you can use it in your helper:

// In PermissionsHelper
$permissions = $this->_View->get('_permissions');