我是 cakephp 新手。我刚刚test
使用下面的行在 cake php 中创建了一个项目
php composer.phar create-project --prefer-dist cakephp/app test
之后我在netbeans中导入这个项目
我更改了数据库配置config/app.php
(只是更改了用户名和密码)
当我运行该项目时,一切都很好,并且 cakephp 页面在那里。
现在我按照互联网上的教程创建了三个文件
src/控制器/PostsController.php
<?php
class PostsController extends \App\Controller\AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
public function view($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Post->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
$this->set('post', $post);
}
}
?>
src/Model/Post.php
<?php
class Post extends AppModel {
}
?>
src/View/Posts/index.ctp
<html>
<body>
<h1>Blog posts</h1>
<?php foreach ($posts as $post): ?>
<p><?php echo $post['Post']['title']; ?> | <?php echo $post['Post']['created']; ?>
<?php endforeach; ?>
<?php unset($post); ?>
</body>
</html>
我也改变了2行config/routes.php
$routes->connect('/', ['controller' => 'Posts', 'action' => 'index', 'home']);
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
$routes->connect('/posts/*', ['controller' => 'Posts', 'action' => 'index']);
当我转到 url http://localhost:8888/test/post或http://localhost:8888/test或http://localhost:8888/test/posts
我总是得到错误
Error: PostController could not be found.
Error: Create the class PostController below in file: src/Controller/PostController.php