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.

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

报告相同问题?

悬赏问题

  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀
  • ¥15 mifare plus卡认证
  • ¥30 LSTM预测结果是一条直线
  • ¥15 stnodeeditor自定义控件
  • ¥15 SDO如何更改STM32的波特率