Welcome Guest, Not a member yet? Register   Sign In
reusing a Model from another web app
#1

[eluser]KeyStroke[/eluser]
Hi,

A friend of mine created a web app from scratch that doesn't follow CodeIgniter's MVC paradigm. His "Models" are basically classes that also include other files or libraries.

Now I've joined him to develop the app, and want to create a stand-alone mobile version that reuses his application's Models (since they're complex, and re-creating them would waste a lot of time).

My question is, what's the best way in your opinion to reuse his Models? both sites will be on the same domain, and we'd rather just point to his Models in the mobile version, so the updates would be immediately effective in both sites (maybe there's a better way to do it though).

What do you think?

Your help is so much appreciated
#2

[eluser]bretticus[/eluser]
As long as his data classes return arrays and scalars, I see no problem. The big benefit to Active Record is that you might be able to switch to another RDBMS later. If that really isn't a big concern, there's no need really.

You might need to extend your loader class to look in his data class folder (If you decide to use the loader object at all.)
#3

[eluser]KeyStroke[/eluser]
Thanks bretticus, but where/how do I include his Models?
#4

[eluser]bretticus[/eluser]
[quote author="KeyStroke" date="1265998598"]Thanks bretticus, but where/how do I include his Models?[/quote]

Refer to "Extending Native Libraries" under Creating Libraries in the manual.

Extend the Loader class with a MY_ version (see the manual.) The only method you need to change (just copy it from the core Loader class) is the model method. Slightly alter it so it checks his data class folder also for "models" to load.

Of course that may be buggy and unnecessarily complex to get working. You might just want to call include in your controller methods and instantiate his classes as you do in native PHP.

Keep in mind, his classes are not extending the CI Model class and so they won't behave like CI models. In fact, if you want to load them with the CI loader, you could even (scratch my first suggestion) create a symlink under application/libraries (perhaps libraries/data) and just load them as libs ( $this->load->library('data/hisclass') )

Of course none of this is tested and I have never had to personally do this. Wink

Good luck!




Theme © iAndrew 2016 - Forum software by © MyBB