敏捷工具包 4 和实现不同的数据库 (mongodb)

发布于 2024-11-26 12:47:11 字数 642 浏览 0 评论 0原文

问题:我需要知道的是我应该如何将不同的数据库(mongodb)合并到 ATK4 中? 具体来说:

  1. 我应该创建一个到数据库的连接并在每个模型中包含 CRUD,还是应该将其抽象到一个库中?
  2. 如果我将其抽象为模型,我将如何从模型内部调用这些方法?

一些注意事项:

  1. 在.net中,明显的答案是抽象它,我在我的项目中使用mongo和asp.net mvc完成了这一点,但当涉及到php时我完全是菜鸟,所以我不确定约定是什么。
  2. Code Igniter 使加载库变得非常容易,我想知道 ATK4 是否也是如此?
  3. 我已阅读了您的所有文档并浏览了测试版文档下的教程。

关于我的一些事情: 我是 php 的菜鸟。我的主要编码框架是 .NET(vb 和 c#(winforms 和 asp(webforms 和 mvc))))

我一直在使用 CodeIgniter 并且非常喜欢它。我的一位同事让我看看 ATK4,我必须说到目前为止我所看到的给我留下了深刻的印象。

但是,如果我要在我的项目中采用 ATK4,我需要能够使用 MongoDB。让我澄清一下:我并不是要求任何人为我编写代码。我只需要一些有关 php 和 atk4 约定的指导。目前网站上关于这些事情的文档有点稀疏(不存在)。

THE QUESTIONS: What I do need to know is how I should go about incorporating a different database (mongodb) into ATK4?
Specifically:

  1. Should I just create a connection to the database and have the crud in every model, or should I abstract it into a library?
  2. If I abstract it into a model, how would I call the methods from inside the model?

Some notes:

  1. in .net, the obvious answer is to abstract it, which I've done on my projects using mongo and asp.net mvc, but I'm a total noob when it comes to php, so I'm not sure what the conventions are.
  2. Code Igniter makes it real easy to load libs, I'm wondering if ATK4 is the same way?
  3. I've read through all of your documentation and skimmed through the tutorial under the beta documentation.

Some things about me: I am a total noob at php. My primary coding framework is .NET (both vb&c# (winforms and asp (both webforms and mvc)))

I've been playing around with CodeIgniter and like it a lot. A coworker of mine asked me to check out ATK4 and I must say I'm impressed with what I've seen so far.

However, if I'm going to adopt ATK4 for my projects I need to be able to use MongoDB. Let me make this clear: I'm not asking for anyone to write the code for me. I just need some guidance on php and atk4 conventions. The documentation on the website about those things are a bit sparse at the moment (non existent).

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

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

发布评论

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

评论(1

笙痞 2024-12-03 12:47:11

你有两个选择,都是抽象的。首先涉及创建网格和其他视图会自动识别的模型和控制器。对于第二个,您需要从 MongoDB 获取数据并将其插入到静态表中。

Mongo 感知视图

这种方法要求您了解模型的运行方式。特别是您需要了解 MVCGrid、setController、setModel 以及 mvc/Controller.php。然后您需要创建自己的控制器。然后,您需要拥有 AbstractView::setModel() 的副本,它使用您的控制器,它将正确地知道如何从 MongoDB 获取数据。

此外,您可能需要扩展 Grid(或 MVCGrid)才能正确传输数据。

完成此操作后,您可以执行以下操作:

$form->setMongoModel('MyModel')->loadData(123);

(如果你使用的是GIT版本,你实际上可以注入这个方法:
https://github.com/atk4/atk4-testsuite /blob/master/page/core.php#L108

半自动方法

在这种方法中,您需要自己从 MongoDB 控制器加载数据并将其输入网格或表单。网格和表单都可以很好地处理静态数据。在这种情况下,您将需要这样的东西:

$c=$this->add('MongoController');
$data=$c->load($my_model,123);
$grid->setStaticSource($data);

其他问题的答案

Code Igniter 是一个很好的框架,但它全局实例化对象。您不太可能需要同一个库的 2 个实例。敏捷工具包允许这样做,并且控制器经常这样使用。因此,在 CI 中,您几乎负责数据管理,而在 ATK4 中,对象相互绑定。这是这些库中方法之间的核心区别。

CI 中的库:

$this->load->library('MyLib');

ATK4 中的库看起来像这样:

$this->api->add('MyLib');

放置

$this->owner->mylib=$this;

在库中是常见的做法,因此您可以更轻松地访问它们。

如果不知道 PHP 开发是如何进行的,您可能会过得更好,因为它在大多数情况下非常依赖于 HTML 模板。

You have two choices, both abstracted. First involves in creating Models and Controllers which Grid and other views would automatically recognise. With second, you would need to fetch data from MongoDB and insert into a static table.

Mongo-aware Views

This approach requires that you know how models operate. Particularly you'll need to understand MVCGrid, setController, setModel as well as mvc/Controller.php. You then would need to create your own controller. You would then need to have copy of AbstractView::setModel() which uses YOUR controller, which will properly know how to fetch data from MongoDB.

Also you would probably need to extend Grid (or MVCGrid) to properly stream data.

Once you have this done, you can do this:

$form->setMongoModel('MyModel')->loadData(123);

(if you are using GIT version, you can actually inject this method:
https://github.com/atk4/atk4-testsuite/blob/master/page/core.php#L108

Semi-automated approach

In this approach you would need to load data from your MongoDB controller yourself and feed it into the grid or form. Both Grids and Forms can work with static data just fine. In this case you would need something like this:

$c=$this->add('MongoController');
$data=$c->load($my_model,123);
$grid->setStaticSource($data);

Answers to your other questinos

Code Igniter is nice framework, but it instantiates objects globally. It's unlikely you would need 2 instances of same library. Agile Toolkit permits that and Controllers are often used like that. As a result you are pretty much in charge of data management in CI while in ATK4 objects bind to each other. It's the core difference between approaches in those libraries.

Library in CI:

$this->load->library('MyLib');

in ATK4 would look like this:

$this->api->add('MyLib');

It's common practice to place

$this->owner->mylib=$this;

inside your libraries, so it's easier for you to access them.

You might be better off without knowing how PHP development happens, it's in most cases very reliant on HTML templates.

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