Welcome Guest, Not a member yet? Register   Sign In
The Controlller and Model same filename -> wrong ?
#28

[eluser]Myles Wakeham[/eluser]
My personal preference is to identify the 'logical' reason for the existence of the Model and name it accordingly. What I mean by this is that I use Models as a basic ORM layer between the database and my application, and in that context they are pure classes.

Since I will instantiate from them, I want to make sure my code is logically readable. I've adopted a data modeling standard for this, since the model classes are OO representations of the database objects for me. This means I use singular referencing to the model, and in the case of controllers which are purely the UI version of this, if I run into a situation where the controller shares a common name with the model, I just make it a plural version.

For example, a 'Client' is represented as a singular entity in my database table. It is mapped to my CI application as a Model class called 'Client' (singular). But in the case where I offer functionality through my app to work with the client (ie. Add one, Delete one, etc.) I reference it as 'Clients' in the controller.

The goal for me is that anyone can read my code and its plain and simple. Since my projects don't seem to be getting any smaller these days, I'm assuming 4-5 developers on the one project with SVN, so each needs to be able to read each other's code base without too much confusion. Adding the word '_model' to a class isn't something I have done, because I wanted to be able to have something like:

Code:
$this->client->check_account_balance()

since it just reads easily. In the case of referencing the instantiated objects in plug-ins or helpers, etc. I create a handle to it that has 'the_' prefixed, so in those cases they read:

Code:
$the_client->check_account_balance()

Again, its all for readability.

My ultimate goal is to be able to have a real vacation where I'm not having to be a slave to my own code creations and I can give it to any other CI/PHP developer and its somewhat self-documenting. I've come to this position after decades and decades of coding experience where I can attest that maintaining code that isn't written this way is just a really bad way to live one's life. These little habits so far have served me well, but if anyone has any suggestions for better ways I can do this (and hence improve my quality of life) I'm all ears.

Myles


Messages In This Thread
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 03:48 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 04:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 04:21 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:30 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:39 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:54 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:10 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:25 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 08:24 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 09:13 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 01:42 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 01:58 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 02:15 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 05:45 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 01:38 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 07:51 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:10 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:33 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:45 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:55 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:14 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:26 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 12:28 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 01:19 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 04:47 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-12-2009, 10:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB