dotelauv682684 2012-08-02 20:14
浏览 30
已采纳

通过CMS在codeIgniter中创建动态控制器

I'm currently building a CMS for a project in codeIgniter and I was wondering if there's any way to create dynamically a controller file in codeIgniter via the CMS when the user create a new page in the database. I don't need to create another model because the tables in the database will be the same, as well as the view. Basicly, all the page in the website (link, title, content etc.) are from the same table. I just want to keep the uri like this (www.mywebsite.com/class/function). Also no routing.

I was looking around the web and the only thing I found close of my request is the CRUD "codegen", but i can't use it online and there's alot of things I just don't need from it.

  • 写回答

1条回答 默认 最新

  • doulai1910 2012-08-02 20:22
    关注

    While it is possible to create a new controller each time the user adds a new page to the database, would it not be better to have a single controller which takes the db id or page name as parameter and loads that page?

    So if the user created two pages called page1 and page2, and you have a controller that is used to serve all dynamic pages named dynamic.php then the urls would be

    www.mysite.com/dynamic/page1
    www.mysite.com/dynamic/page2
    

    Creating a controller each time the user creates a page is a big overhead, and also would require lots of code to properly implement, like deleting the controller when the user deletes the page from database, for instance. And I think to provide a coding solution within SO would be cumbersome.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改