存根,cakePHP 中的动态主页
我正在为一位客户开发一个网站,该客户希望能够更新修改其内容。简述是允许他们编辑页面,但不能创建或删除页面。对于这个网站,我决定使用 cakePHP,因为我听说过一些好东西。
首先,快速解释一下我的设置。我有一个名为“内容”的表,其中存储每个页面的内容。该表有一个 pid、一个 varchar“标题”、一个 varchar“slug”和一个长文本“正文”。它们都很不言自明,每个页面都有自己的行,正文将是一个简单的 HTML 转储。
我遇到了两种情况。首先,是设置主页。 Cake的默认页面是基于home.ctp的页面,但它是静态的。目前我作为主页的页面位于 localhost/alc/contents/view/2。我知道这与路由有关,但是当我需要每个细节时,大多数示例都给出了一半的解决方案:P
第二个问题是页面的slugs。当前每个页面都位于 /contents/view/id 下,我希望将其作为数据库中的 slug。每次我尝试更改此设置(即修改索引中的视图链接)时,我都会收到错误而不是页面内容。
对此的任何帮助将不胜感激,因为有两件事我似乎无法正确掌握。谢谢!
顺便说一句,您可以在 http://www.roberttilt.name/web- 查看该网站开发/ALC_proto/
I'm working on a site for a client that wants to be able to update modifying their content. The brief was to allow them to edit pages, but not create or delete them. For the site I decided to work with cakePHP, as I've heard good things.
First up, a quick explanation of my setup. I've got a single table, called 'contents', in which i'm storing each page's content. The table has a pid, a varchar 'title', a varchar 'slug' and a longtext 'body'. They're all pretty self explanitory, Each page will have it's own row, and body will be a simple HTML dump.
I've got two situations that I am having trouble with. Firstly, is setting the homepage. Cake's default is the page based on home.ctp, but that is static. Currently the page I was as the homepage is at localhost/alc/contents/view/2. I understand this is something to do with the routing, but most examples out there give half the solution, when I need every detail :P
The second problems is the slugs of the pages. Each page is currently under /contents/view/id, and i'd like this to be the slug in the database instead. Each time i try to change this (i.e. modify the view link in my index), I get an error rather than the page's content.
Any help on this would be appreciated, as there are the two things I cannot seem to grasp properly. Thanks!
By the way, you can view the site at http://www.roberttilt.name/web-dev/ALC_proto/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第一个问题,您需要打开 /app/config/routes.php 并更改主页的行。即:
需要成为
在您的控制器文件 /app/controllers/contents_controller.php 中转到操作视图并将其更改为接受空 id ie
这样,如果未提供 id 或 slug,您将加载主页。如果加载其中之一,只需使用它来加载所需网页的内容即可。
您的链接将如下所示:
链接将转换为
也许您必须查看Cookbook。
For the first question you need to open the /app/config/routes.php and change the line which is for the home page. i.e.:
need to become
In your controller file /app/controllers/contents_controller.php go to action view and change it to accept empty id i.e.
This way if the id or slug are not provided you are loading the home page. If one of them is loaded, just use it to load the contents of the desired web page.
Your links will look like:
The link will be converted to
Probably you have to take a look on the Cookbook.