简体   繁体   English

在CodeIgniter中的模型内加载库是个好主意吗?

[英]Is loading libraries within models in CodeIgniter a good idea?

I'm using a customly created MySQL input sanitization library in one of my controllers, which makes a mess, using it in the model would be much easier, but I don't wan't to defy any best-practice principles out there either. 我在一个控制器中使用了一个自定义创建的MySQL输入清理库,这很麻烦,在模型中使用它会容易得多,但是我也不想违背任何最佳实践原则。 So is it a good idea? 那是个好主意吗?

I ran into this myself. 我自己遇到了这个。 You know what? 你知道吗? If it makes your application work, screw conventions. 如果它使您的应用程序正常工作,请拧紧约定。 If you need to call a chunk of code that you've already written (and you know it will work), then there's no good reason to follow "best-practices" and do something that will effectively make your app slower/less efficient/etc. 如果您需要调用已经编写的代码块(并且知道它会工作),则没有充分的理由遵循“最佳实践”并做一些有效地使您的应用变慢/效率降低/等等

The whole point of best practices is to write code in the best way. 最佳实践的重点在于以最佳方式编写代码。 If the best way that something seems like it should be done is by calling a library from a model, go for it. 如果看起来应该完成某件事的最好方法是从模型中调用一个库,那就去做吧。 Best practices are not a universal law. 最佳实践不是普遍适用的法律。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM