代码点火器路由
我目前正在为客户开发 CMS,我将使用 Codeigniter 进行构建,这只是一个快速项目,所以我并不是在寻找强大的解决方案。
为了创建页面,我要保存页面详细信息,并根据与 mysql 表中的 slug 匹配的 slug 提取正确的页面。
然而,我的问题是,要使其工作,我必须将这个 slug 从控制器的 URL 传递到模型,这意味着我在 URL 中也有我不希望的控制器,是否可以删除来自带有路由的 URL 的控制器?
所以
/页面/我们的故事
变成
/我们的故事
这可能吗
I am currently working on CMS for a client, and I am going to be using Codeigniter to build on top of, it is only a quick project so I am not looking for a robust solution.
To create pages, I am getting to save the page details and the pull the correct page, based on the slug matching the slug in the mysql table.
My question is however, for this to work, I have to pass this slug from the URL the controller then to the model, this means that I also have too have the controller in the URL which I do not want is it possible to remove the controller from the URL with routes?
so
/page/our-story
becomes
/our-story
Is this possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议这样做。
假设您有:控制器“页面”/方法“显示”
或方法是我不推荐的索引,如果您有新闻之类的内容,请添加以下内容。
就是这样。
I would recommend to do it this way.
Let's say that you have : controller "page" / Method "show"
or method is index which I don't recommend, and if you have something like news, add the following.
That's it.
是的,当然。我最近刚刚自己构建了一个 Codeigniter 驱动的 CMS。路由的全部目的是改变 URL 的外观和功能。它可以帮助您摆脱控制器/函数/参数/参数范式,并让您选择您想要的 url 的外观。
$routes['404_override'] = "pages";
然后所有对不存在的控制器的调用都将发送到您的控制器,然后您可以检查 URL 块是否存在。您还应该将页面设置为默认控制器值。请参阅我几个月来对类似问题的回答返回我在 Codeigniter CMS 中使用的示例代码和工作代码。
Yes, certainly. I just recently built a Codeigniter driven CMS myself. The whole purpose of routes is to change how your urls look and function. It helps you break away from the controller/function/argument/argument paradigm and lets you choose how you want your url's to look like.
$routes['404_override'] = "pages";
and then all calls to controllers that don't exist will be sent to your controller and you then can check for the presence of URL chunks. You should also make pages your default controller value as well.See my answer for a similar question here from a few months back for example code and working code that I use in my Codeigniter CMS.
这是我在最近的项目中用于实现此目的的代码。我从什么地方借来的;不记得在哪里了。
然后,我的
index
函数就是您放置page
函数的位置。Here's the code I used in a recent project to achieve this. I borrowed it from somewhere; can't remember where.
Then, my
index
function is where you would put yourpage
function.