CakePhp 3.0 - 一些自由操作的授权

CakePhp 3.0 - Authorization with some free action

我对 CakePhp 框架完全陌生,所以我正在学习基础教程。到目前为止一切顺利,我为我的模型构建了脚手架,身份验证工作正常,但我有点过分:我想允许一个操作(例如 'index'),即使对于未经身份验证的用户也是如此.

我怀疑它一定与 "BeforeFilter()" 有关系,但我尝试过的任何解决方案都没有奏效 - 可能是因为它们适用于 CPHP 2.0,and/or 我很笨 .

代码在这里,虽然它不是特别有趣,因为它是由脚手架机制生成的。

<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * Frutta Controller
 *
 * @property \App\Model\Table\FruttaTable $Frutta
 */
class FruttaController extends AppController
{

    /**
     * Index method
     *
     * @return void
     */
    public function index()
    {
        $this->set('frutta', $this->paginate($this->Frutta));
        $this->set('_serialize', ['frutta']);
    }

//cut..
}

使用以下内容:

function beforeFilter() {
     parent::beforeFilter();
     $this->Auth->allow('index'); //allow index without authentication 
}

参考:http://book.cakephp.org/3.0/en/controllers/components/authentication.html#making-actions-public