Welcome Guest, Not a member yet? Register   Sign In
Common function
#7

I do not think you are missing anything, as I too have wondered exactly the same thing.

Sure, you do not have to create a model function when you decide you want to get, say, user details from a user table. You just use the generalised model to get a row from any table you choose. But I have found that very quickly these generalised models and table interactions become more and more bulky as complexity grows, and less and less useful. In the end, with so many special cases, the time saved is negligible. So I stopped using them altogether. (I had done my own one, as I really thought the idea was a good one, but after one project, I abandoned it as unnecessary bloat).

Also, if I change a table (its name, columns, indexes, whatever) I want to update just one or a few models that refer to the table. Not go through every controller that calls the function to alter the name.

Finally, I prefer...

PHP Code:
$user_details $this->user_model->get_user_details(); 

...in my controller. There is no reference here to anything about how the user is stored, what is stored or where (session data, database, files etc).

Now if my user table changes, I update the user model - all done.

Why would I want my user model to access another model to access the database? Just to save a bit of typing? No. And for ease of maintenance, I do not think DRY means force every database call through yet another abstraction layer. It is only about 5% of the time that I have to write an SQL query directly for complex queries. For the vast majority of queries, the query builder is stable, simple, safe, fast, concise and ultimately easy to maintain.

But perhaps like you rtenny, I am missing something important about this. And after 30 years of programming, imagine all the lessons you have learned about coding that even you probably do not realise you apply. You just do it naturally. And to me, naturally, this seems like a nice to play with but actually completely unnecessary layer.

Best wishes,

Paul.

PS the only place I can see this being useful is if you need to record every transaction through a database, like for financial transaction recording. But if that was the case, you would not do it through your application code, but separately on the database itself. (I have never done this but I read some really interesting stuff a while back about how our databases can do such things.)
Reply


Messages In This Thread
Common function - by Myster - 06-24-2017, 04:03 AM
RE: Common function - by skunkbad - 06-24-2017, 07:39 AM
RE: Common function - by Wouter60 - 06-25-2017, 05:43 AM
RE: Common function - by rtenny - 06-26-2017, 03:11 AM
RE: Common function - by Wouter60 - 06-26-2017, 03:53 AM
RE: Common function - by rtenny - 06-26-2017, 05:40 AM
RE: Common function - by PaulD - 06-26-2017, 10:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB