Cakephp走错路

时间:2016-07-01 06:17:48

标签: cakephp-3.0

我正在开发Cakephp。在default.ctp中,我给出了一个像

这样的链接
  <li><?= $this->Html->link('List',['controller' => 'Products', 'action' => 'index']) ?></li>

我还有一个ProductsController.php。

<?php

namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;

class ProductsController extends AppController {

public function initialize(){
parent::initialize();
$this->loadcomponent('Flash');
}
public function index(){
$products = $this->Products->find('all');
$this->set(compact('products'));
}

但是当我点击该链接时,它会给出错误,如

  1. 错误:找不到WebrootController。
  2. 错误:在文件中创建下面的WebrootController类:src / Controller / WebrootController.php
  3. 单击切换参数时会显示

    object(Cake\Network\Request) {
    params => [
        'plugin' => null,
        'controller' => 'Webroot',
        'action' => 'products',
        '_ext' => null,
        'pass' => [],
        '_matchedRoute' => '/:controller/:action/*',
        'isAjax' => false
    ]
    data => []
    query => []
    cookies => [
        '__atuvc' => '1|21'
    ]
    url => 'webroot/products/'
    base => '/cakephp'
    webroot => '/cakephp/'
    here => '/cakephp/webroot/products/'
    trustProxy => false
    

    请帮我解决这个错误。

1 个答案:

答案 0 :(得分:0)

检查应用程序根文件夹和webroot文件夹中是否存在两个.htaccess文件。

并确保允许.htaccess覆盖,并且对于正确的DocumentRoot,AllowOverride设置为All

http://book.cakephp.org/3.0/en/installation.html#url-rewriting