agile toolkit 4 and implementing a different database (mongodb)
THE QUESTIONS: What I do need to know is how I should go about incorporating a different database (mongodb) into ATK4? Specifically:
- Should I just create a connection to the database and have the crud in every model, or should I abstract it into a library?
- If I abstract it into a model, how would I call the methods from inside the model?
Some notes:
- 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.
- Code Igniter makes it real easy to load libs, I'm wondering if ATK4 is the same way?
- I've read through all of your documentation and skimmed through the tutorial under the beta documentation.
Some thing开发者_开发百科s 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).
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.
精彩评论