Welcome Guest, Not a member yet? Register   Sign In
Just what is a "Model" supposed to be in CI?
#11

[eluser]BrianDHall[/eluser]
To the top, you are correct that ActiveRecord is just a database abstraction layer with helper functions. You seem to have wanted ORM - it might be a moot point, but I think DataMapper Overzealous Extension (DMZ)does exactly what you want and it is pretty much just a drop-in ORM solution.

So for instance:

Code:
$u = new User();
$u->username = 'Billy';
$u->password = 'cleartext';

$g = new Usergroup('admin');

if ($u->save($g))
{
// account created and saved correctly)
}

That bit of code creates an entry in the database, gets the usergroup desired for the user, saves the account and relates the user to the usergroup (stored in a separate table).

In DMZ you can set validation rules like CI's form validation class, so that password is automatically hashed using whatever method you want (a simple sha1 hash or a custom salted solution, etc).

Your perceptions from the tutorials are correct, they are not much observing strong OOP principles and models are used like flimsy CRUD handlers.

This is not a weakness of CI, it's just proof of the simplicity of the examples. Real-world business apps built in CI (every one I've ever seen) uses models much more as they should be, to fully encapsulate data AND to control its manipulation, handling, and ensure its safe and efficient functioning.

ORM, such as DMZ, just handles a large portion of a model. It is an easy mistake to make, under-estimating the power of models, but DMZ showed this to me as it automated so much that I found my models totally empty and it seemed like such a waste. That is when it became clear to me I'm missing something, which is when I began to appreciate the deeper power of models.

If you really think its easier and faster to build an MVC/ORM framework from scratch when you need it...well, wow, you've really missed the point and power of CI entirely. Perhaps it really isn't for you, as it isn't for everyone (Ramus Lerdorf states CI is the best framework he has seen...but he goes on to say he doesn't like frameworks, so the less there is the better the framework is in his opinion) - but I think you are completely going about CI the wrong way.

If you want MVC, CI has everything you need - and if you want ORM functionality, it's as simple as dropping an extension in and going for it. But its power, and some thing its weakness, is CI won't complain if you do something entirely ignorant or inadvisable. Unlike Cake, it will happily let you ignore the unique roles of Views and Models and let you treat your controllers like little more than big functional libraries with only the tiniest connection to object oriented principles.

The fact is, ORM is something else that would need to be learned to get started. If you had to learn OOP, MVC, and ORM all just to get started with CI...hell, I wouldn't use it at all, I don't have time for months of 'experimenting' or 'learning curve' just to start producing something.

CI lets you start within minutes and you can use all your previous PHP experience. It won't complain if you do things 'wrong', it just helps you get done faster - time you can easily then use to go back and make things better with what you have learned in the mean time.

CI is about productivity, not about forcing its opinions and principles on you. If you want to be forced to use all the tools available - whether you want to or not - CI really isn't the right framework for you whatsoever.


Messages In This Thread
Just what is a "Model" supposed to be in CI? - by El Forum - 05-01-2009, 03:02 PM
Just what is a "Model" supposed to be in CI? - by El Forum - 05-03-2009, 05:22 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 05-03-2009, 07:11 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 05-03-2009, 07:17 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 08-19-2009, 07:53 PM
Just what is a "Model" supposed to be in CI? - by El Forum - 08-20-2009, 05:47 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 08-20-2009, 06:25 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 07:42 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 07:46 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 07:53 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 09:12 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 09:45 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 09:56 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 10:07 AM
Just what is a "Model" supposed to be in CI? - by El Forum - 09-29-2009, 11:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB