CodeIgniter CRUD视图抽象(CodeIgniter CRUD view abstraction)

编程入门 行业动态 更新时间:2024-10-21 18:32:08
CodeIgniter CRUD视图抽象(CodeIgniter CRUD view abstraction)

我正在使用CodeIgniter构建一个CMS,我对处理各种CRUD视图的最佳方法感到难过。 鉴于我的网址类似于......

mydomain.com/admin/app/content/pages/edit

...'admin'是我的控制器而'app'是我的操作方法,我目前将段3,4和5映射到实际目录/文件,如下所示:

/views /admin /content /pages list_view.php edit_view.php add_view.php /banners list_view.php edit_view.php add_view.php

需要注意的是,我需要根据调用的页面调用不同的非CRUD模型方法,因此我的app()动作方法开始有一个令人讨厌的if..else块。 此外,由于不同的表数据,每个部分的视图看起来会有所不同,所以我看不出如何避免拥有一堆视图页面。 显然所有这些的缺点是1)我重复了很多代码,2)如果我添加一个新的管理部分,我必须在物理上制作一大堆新目录,并在if ...中添加一个新部分。其他块。

所以我的问题是:

如何减少我正在创建的目录和查看页面的数量? list_fields()或field_data()方法可以适用于任何自动化吗?

我的一个想法是分析我正在与之交互的表,创建一个动态关联数组,定义我想要公开的字段以及它应该是的表单元素的类型,然后将其传递给公共视图。 思考? 缺陷?

谢谢!

I'm building a CMS using CodeIgniter and I'm stumped on the best way to go about handling the various CRUD views. Given that my URL is similar to...

mydomain.com/admin/app/content/pages/edit

...where 'admin' is my controller and 'app' is my action method, I currently map segments 3, 4, and 5 to actual directories/files, like so:

/views /admin /content /pages list_view.php edit_view.php add_view.php /banners list_view.php edit_view.php add_view.php

One caveat is that I need to call different non-CRUD model methods depending on which page is being called, so my app() action method is starting to have have a nasty if..else block. Also, each section's views are going to look different, because of different table data, so I don't see how I can avoid having a bunch of view pages. Obviously the downside of all this is that 1) I'm repeating a lot of code, and 2) if I add a new admin section I have to physically make a slew of new directories and add a new portion to the if...else block.

So my questions are:

How can I reduce the number of directories and view pages I'm creating? Can list_fields() or field_data() methods lend itself to any automation?

One idea I had was to profile the table I'm interacting with, create a dynamic associative array that defines which fields I want to expose as well as the type of form element it should be, and then pass that off to a common view. Thoughts? Flaws?

最满意答案

虽然我很欣赏这可能不是您问题的直接答案,但它可能为您提供设计CRUD的基础。 我现在已经使用了GroceryCRUD很长一段时间了,并且基本和高级CRUD操作都非常发誓。 它的设计和构建设计得非常好,除了定制的文件结构外,它似乎可以满足您的所有需求。 可以很容易地修改CRUD以合并您正在寻找的文件/ URL结构。

@see http://www.grocerycrud.com/

While this may not directly answer to your question, it may provide you with a basis on which to design your CRUD. I've used GroceryCRUD for quite a while now and pretty much swear by it for basic and advanced CRUD operations. It's pretty well designed and built and apart from the bespoke file structure, would appear to offer all that you're looking for.

The CRUD could easily be modified to incorporate the file/url structure you're looking for too.

See http://www.grocerycrud.com/

更多推荐

本文发布于:2023-08-06 15:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1450350.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   抽象   CRUD   CodeIgniter   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!