将现有的Cakephp 3项目设置为本地XAMPP

时间:2018-01-31 07:48:06

标签: php cakephp xampp cakephp-3.0

所以我将一个名为CakeApp的现有Cakephp 3项目设置到我的本地XAMPP。我将CakeApp文件夹放在C:\\xampp\htdocs\中,我可以在http://localhost/CakeApp中访问其主页面。它会自动将我重定向到http://localhost/CakeApp/users/login,这是假定的主页面。我试图访问Cakephp的主src\Pages\home.ctp,但首先检查项目是否已在我的本地XAMPP中成功设置。所以在config\routes.php,我改变了:

Router::scope('/', function ($routes) {

$routes->connect('/',
        ['controller' => 'Pages', 'action' => 'index']
    );

$routes->fallbacks('DashedRoute');     });

Router::scope('/', function ($routes) {

$routes->connect('/',
        ['controller' => 'Pages', 'action' => 'home']
    );

$routes->fallbacks('DashedRoute');    });

现在http://localhost/CakeApp正在给我一个Error: The requested address '/CakeApp/' was not found on this server.

所以在src\Pages\home.ctp,我评论说:

if (!Configure::read('debug')):
    throw new NotFoundException();
endif;

尽管如此,它仍然给了我同样的Error: The requested address '/CakeApp/' was not found on this server.。所以在src\Controller\PagesController.php中,我发现home没有任何操作。所以我创建了:

public function home() {
}

现在,转到http://localhost/CakeApp会自动将我重定向到http://localhost/CakeApp/users/login。我试图访问home.ctp,它提供了有关Cakephp项目设置的信息。 任何帮助将不胜感激。非常感谢你。

1 个答案:

答案 0 :(得分:0)

你能评论routes.php中的所有代码,然后替换为这段代码

<?php

use Cake\Core\Plugin;
use Cake\Routing\Router;

Router::defaultRouteClass('Route');

Router::scope('/', function ($routes) {

    $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
    $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
    $routes->fallbacks('InflectedRoute');
});

Router::extensions('json', 'xml');
/**
 * Load all plugin routes.  See the Plugin documentation on
 * how to customize the loading of plugin routes.
 */
Plugin::routes();
?>