在控制器cakephp 3中使用自定义助手

时间:2016-12-02 10:48:20

标签: php cakephp model-view-controller cakephp-3.0

我正在使用cakephp v3并想询问如何在custom helper中使用controller

我试过下面的代码。

namespace App\Controller;

use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
use App\Controller\AppController;
use Cake\Event\Event;
use Cake\Network\Request;
use Cake\ORM\TableRegistry;
use Cake\Auth\DefaultPasswordHasher;
use Cake\View\View;
use Cake\View\Helper\HtmlHelper;
use Cake\View\Helper\UrlHelper;
use Cake\View\Helper;
use App\View\Helper\SecurityHelper;

/**
 * Static content controller
 *
 * This controller will render views from Template/Pages/
 *
 * @link http://book.cakephp.org/3.0/en/controllers/pages-controller.html
 */
class PagesController extends AppController {
 function beforeFilter(Event $event) {
        parent::beforeFilter($event);

        $this->viewBuilder()->helpers(['Security']);
}

 public function receiveSaving() {
        pr(($this->request->params['id'])); //die;
        pr($this->Security->decrypt('7JCdO3vIqAU_EQUALS_')); die;
        $this->viewBuilder()->layout('front');
        $this->set('title', '');
        $this->set('meta_title', '');
        $this->set('meta_description', '');
        $this->set('meta_keywords', '');
        //$this->render('savings_bond_result');
    }

并低于错误。

  

错误:在布尔文件上调用成员函数decrypt()   D:\ xampp \ htdocs \ myproject \ src \ Controller \ PagesController.php行:204

我尝试过其他一些方法,比如

$Security = new SecurityHelper(new \Cake\View\View());
pr($Security->decrypt('7JCdO3vIqAU_EQUALS_')); die;
  

错误:Class' App \ Controller \ SecurityHelper'找不到文件   D:\ xampp \ htdocs \ myproject \ src \ Controller \ PagesController.php行:204

1 个答案:

答案 0 :(得分:0)

$customdtfhelper = new \App\View\Helper\CustomDtfHelper(new \Cake\View\View());
$customdtfhelper->method_name();
相关问题