cakePHP 中的动态页面
所以我一直在使用 cakePHP 创建我的第一个客户端网站,但遇到了问题。
我正在尝试创建一个类似于 WordPress 的系统,您可以在其中创建新页面(简单的标题、slug 和内容),并将它们提供给它们的 slug 地址(即“关于”将在 mysite.com/about 上提供)。
我创建了自己的控制器和“页面”模型(覆盖核心页面控制器),并设置了简单的功能(view、admin_add、admin_delete)。我的模型很简单,只有 $name ,这样它就可以连接到数据库。
我很确定我的问题出在 config/routes.php 中。这是我当前正在使用的代码:
App::import('model', 'Page');
$Page = new Page();
$pages = $Page->find('list', array('fields' => array('id', 'slug')));
Router::connect('/:pages', array('controller' => 'pages'), array('Page' => implode($pages, '|')));
但它不起作用。当我访问我拥有的页面(即 mysite.com/newpage)时,它告诉我找不到 newpage 控制器。
请帮忙!我的截止日期很紧:)
谢谢,
~harley
So I've been creating my first client website with cakePHP, and have run into a problem.
I'm trying to create a system similar to WordPress where you can create new pages (simply title, slug and content), and they are served up to their slug address (i.e. About will be available at mysite.com/about).
I've created my own controller & model for 'Pages' (overwriting the core pages controller), and have set up simple functions (view, admin_add, admin_delete). My model is simple, just the $name so it can connect to the db.
I'm pretty sure my problem lies in config/routes.php. Here is the code I'm currently using:
App::import('model', 'Page');
$Page = new Page();
$pages = $Page->find('list', array('fields' => array('id', 'slug')));
Router::connect('/:pages', array('controller' => 'pages'), array('Page' => implode($pages, '|')));
It just doesn't work though. When I visit an page I have (i.e. mysite.com/newpage), it tells me the newpage controller can't be found.
PLEASE HELP! I'm on a tight deadline :)
Thanks,
~harley
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要扩展 CakeRoute 类。将您的自定义模型代码放在那里,然后将该类名称传递给routes.php 中的路由定义。routes.php
看起来像这样。
然后在 libs/routes/my_custom_route.php
}
You need to extend the Class CakeRoute. Put your custom model code in there, and then pass that class name to your route definition in routes.php
routes.php would look something like this.
Then over in libs/routes/my_custom_route.php
}