PHP商业项目函数定义

发布于 2024-09-03 02:51:05 字数 901 浏览 1 评论 0原文

目前我正在使用 PHP 开发一个商业项目。我认为这个问题并不真正适用于所有编程语言的 PHP,只是想讨论你们如何解决它。

我在 MVC 框架(CodeIgniter)中工作。

模型类中的所有数据库事务代码。

以前,我用不同的函数名称分隔不同的搜索条件。 只是一个例子

function get_student_detail_by_ID($id){}
function get_student_detail_by_name($name){}

,您可以看到该函数实际上可以合并为一个,只需为其添加一个参数即可。但是你急于完成的项目,你不会回头看以前有过什么类似的功能,只需做一些改变就可以达到目标。在这种情况下,我们发现那里的功能很多并且很难维护。

最近,我们尝试将实体分组到一个终极搜索中 像这样,

function get_ResList($is_row_count=FALSE, $record_start=0, $arr_search_criteria='', $paging_limit=20, $orderby='name', $sortdir='ASC')

我们尝试使这个函数适合所有搜索条件。然而,我们的系统越来越大,搜索条件不再多1-2个表。它需要与具有不同目的的其他表连接。 我们所做的是使用IF ELSE,

if(bla bla bla)
{
   $sql_join = JOIN_SOME_TABLE;
   $sql_where = CONDITION;    
}

最后我们发现这个功能很难维护。调试也非常困难。

我想问问你的意见,他们解决这类问题的商业解决方案是什么,如何定义一个函数以及如何修改它。我认为这就是链接项目管理技巧。希望您愿意与我们分享。

谢谢。

Currently I am working with a commercial project with PHP. I think this question not really apply to PHP for all programming language, just want to discuss how your guys solve it.

I work in MVC framework (CodeIgniter).

all the database transaction code in model class.

Previously, I seperate different search criteria with different function name.
Just an example

function get_student_detail_by_ID($id){}
function get_student_detail_by_name($name){}

as you can see the function actually can merge to one, just add a parameter for it. But something you are rushing with project, you won't look back previously got what similar function just make some changes can meet the goal. In this case, we found that there is a lot function there and hard to maintenance.

Recently, we try to group the entity to one ultimate search
something like this

function get_ResList($is_row_count=FALSE, $record_start=0, $arr_search_criteria='', $paging_limit=20, $orderby='name', $sortdir='ASC')

we try to make this function to fit all the searching criteria. However, our system getting bigger and bigger, the search criteria not more 1-2 tables. It require join with other table with different purpose.
What we had done is using IF ELSE,

if(bla bla bla)
{
   $sql_join = JOIN_SOME_TABLE;
   $sql_where = CONDITION;    
}

at the end, we found that very hard to maintance the function. it is very hard to debug as well.

I would like to ask your opinion, what is the commercial solution they solve this kind of issue, how to define a function and how to revise it. I think this is link project management skill. Hope you willing to share with us.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花辞树 2024-09-10 02:51:05

如果您使用的是 codeigniter,只需使用:

http://www.overzealous.com/dmz/

我什至不知道没有它我会做什么。

If you're using codeigniter, just use:

http://www.overzealous.com/dmz/

I don't know what I even used to do without it.

妖妓 2024-09-10 02:51:05

恭喜,您发明了一个 ORM :)

有大量的商业 ORM 解决方案,但在我看来,它们并不比你的。我会选择好的 SQL。

Congratulations, you have invented an ORM :)

There are plenty of commercial ORM solutions but, in my opinion, all they no better than yours. And I'd go for good ol' SQL.

謸气贵蔟 2024-09-10 02:51:05

在我对 ORM 与 Active Record 进行了一些研究之后。对于我的情况,我没有找到很多帮助,通过切换到 ORM 会更好地帮助我。

我发现 ORM 在读取数据方面做得不是很好。但擅长创建、更新和删除。

我当前的解决方案是每个模型在传递给 $this->db->query() 之前重新编译我自己的 OR_WHERE() / AND_WHERE()。它更容易维护和定制。

After I did some research on ORM vs Active Record. For my situation I didn't find a lot of help by switching to ORM will help me better.

I found out that ORM is not do very in READ data. But good in Create, Update, and Delete.

My current solution is every model recompile the my own OR_WHERE() / AND_WHERE(), before pass to the $this->db->query(). It is more easy to maintain and customize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文