CakeDC\Users\View\Helper\AuthLinkHelper::link PHP Method

    public function link($title, $url = null, array $options = [])
    {
        $linkOptions = $options;
        unset($linkOptions['before'], $linkOptions['after'], $linkOptions['allowed']);
        $allowed = Hash::get($options, 'allowed');
        if ($allowed === false) {
            return false;
        }
        if ($allowed === true || $this->isAuthorized($url)) {
            return Hash::get($options, 'before') . parent::link($title, $url, $linkOptions) . Hash::get($options, 'after');
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * Test link
  *
  * @return void
  */
 public function testLinkAuthorized()
 {
     $view = new View();
     $eventManagerMock = $this->getMockBuilder('Cake\\Event\\EventManager')->setMethods(['dispatch'])->getMock();
     $view->eventManager($eventManagerMock);
     $this->AuthLink = new AuthLinkHelper($view);
     $result = new Event('dispatch-result');
     $result->result = true;
     $eventManagerMock->expects($this->once())->method('dispatch')->will($this->returnValue($result));
     $link = $this->AuthLink->link('title', '/', ['before' => 'before_', 'after' => '_after', 'class' => 'link-class']);
     $this->assertSame('before_<a href="/" class="link-class">title</a>_after', $link);
 }
All Usage Examples Of CakeDC\Users\View\Helper\AuthLinkHelper::link
AuthLinkHelper