为什么index.ctp呈现为文本而不是html/php?
我尝试自己研究这个问题一段时间,但似乎无法找到解决方案。我正在学习 CakePHP 博客教程,在本节中: http:// book.cakephp.org/view/1536/Creating-Post-Views
我使用 CakePHP 给出的代码创建了 index.ctp 文件。然后,当我在 Safari 中打开 index.ctp 文件时,它只显示 CakePHP 给出的代码。它不呈现任何 HTML,也不从数据库中提取博客数据。
如果我将扩展名从 .ctp 切换到 .php,它会呈现 HTML,但不会从数据库中提取博客数据。我的数据库已连接并且具有正确的信息。我认为 .ctp 扩展名有问题?没有把握。还有其他人遇到过这种问题吗?
I tried researching this question on my own for awhile, but can't seem to pinpoint the solution. I'm working through the CakePHP Blog Tutorial, and at this section: http://book.cakephp.org/view/1536/Creating-Post-Views
I create the index.ctp file with the code given by CakePHP. Then, when I open the index.ctp file in Safari, it simply shows the code given by CakePHP. It doesn't not render any HTML, nor does it pull the blog data from the database.
If I switch the extension from .ctp to .php, it renders HTML but it does not pull blog data from the database. My database is connected and has the correct information. I think there is an issue with the .ctp extension? Not sure. Has anyone else run into this kind of issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,尝试这个网址:
http://localhost/posts/index
其次,您的开发环境中可能没有启用 mod_rewrite。
例如,在 ubuntu 上,您可以像这样启用它:(
编辑:之后重新启动 apache)
第三:
检查你的.htaccess,你需要启用mod_rewrite。另请检查教程/cakePHP 文档,了解您是否错过了有关 .htaccess 和重写规则的任何步骤。
First, try this url:
http://localhost/posts/index
Second, you may have not mod_rewrite enabled in your development environment.
On ubuntu for example you can enable it with like this:
(EDIT: restart apache afterwards)
Third:
Check your .htaccess, you need mod_rewrite to be enabled. Also check the tutorial/cakePHP documentation to find out if you missed any step concerning .htaccess and the Rewrite Rules.
RedEye,
RedEye,
请确保您的站点可用/默认文件中的
AllowOverride
设置为“全部”(而不是“无”)。Please make sure the
AllowOverride
is set to All (instead of None) in your sites-available/default file.