Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 2.01 KB

AuthLinkHelper.md

File metadata and controls

55 lines (42 loc) · 2.01 KB

AuthLinkHelper

The AuthLink Helper has some methods that may be needed if you want to improve your templates and add features to your app in an easy way. This helper provide two methods that allow you to hide or display links and postLinks based on the permissions file. No more permissions check in your views ! If the permissions file is update, you do not have to replicate the permissions logic in the views.

Setup

Enable the Helper in src/view/AppView.php:

class AppView extends View
{
    public function initialize()
    {
        parent::initialize();
        $this->loadHelper('CakeDC/Users.AuthLink');
    }
}

Link

You can use this helper like the initial cakePhp HtmlHelper link method :

In templates

- echo $this->Html->link(__d('cake_d_c/users', 'List Users'), ['action' => 'index'])
+ echo $this->AuthLink->link(__d('cake_d_c/users', 'List Users'), ['action' => 'index'])

PostLink

You can use this helper like the initial cakePhp FormHelper postLink method :

In templates

- echo $this->Form->postLink(__d('cake_d_c/users', 'Delete'), ['action' => 'delete', $user->id], ['confirm' => __d('cake_d_c/users', 'Are you sure you want to delete # {0}?', $user->id)])
+ echo $this->AuthLink->postLink(__d('cake_d_c/users', 'Delete'), ['action' => 'delete', $user->id], ['confirm' => __d('cake_d_c/users', 'Are you sure you want to delete # {0}?', $user->id)])

Before and After

The link method allow you to add two additional parameters in the options array. Those two parameters are before and after to quickly inject some html code in the link, like icons etc

echo $this->AuthLink->link(__d('cake_d_c/users', 'List Users'), ['action' => 'index', 'before' => '<i class="fas fa-list"></i>']);

Before and After are only implemented for the link method.