CodeIgniter Forums

Full Version: How to structure this efficiently?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jaswinder_rana[/eluser]
I am creating a small realty site. it has tables like

feature_groups (Kitchen, Bathroom)
features (Sink, Shower)
property_types (Detached)
property_for (Sale, Rental)
properties (address, bedrooms etc.)
properties_features (1-2 means first property has Shower which is in Kitchen).

Now, my problem is how to write controllers for it. Should everyone be in single controller?

I was thinking one controller (and model) for each table to list, add, modify data for every thing. Will that be too much?

Individual controller/model will simplify things but I don't want to have too many controllers/models and make a mess while trying to simplify it.

Please suggest

El Forum

[eluser]Colin Williams[/eluser]
You have one type of object: a property. Features and types are sub-objects of properties. I would keep it all in one Property controller and one Property model.

El Forum

[eluser]jaswinder_rana[/eluser]
But then I'll have to append table name to my functions to differentiate.

like for get() function I'd have to 5 names like get_feature_groups() and so on.

If I keep them different then I can name them similar and logically.

I am not saying your idea is not good. I am just throwing out ideas so I don't miss anything.

Is there other way in CI to do this logically without going in to long function names?

Thanks

El Forum

[eluser]kgill[/eluser]
When you start thinking about coding something based on how much you have to type for a function name that's the point where you started going the wrong way down a one way street. Design decisions should be driven by what the design dictates not amount typed. Besides you don't really gain anything by it:

Code:
$this->load->model('Feature_Groups');
$this->load->model('Features');
$this->load->model('Property_Types');
$this->load->model('Property_For');
$this->load->model('Properties');
$this->load->model('Properties_Features');

$something = $this->Features->getAll();
$somethingelse = $this->Property_Types->getAll();

vs

$this->load->model('Listing');

$something = $this->Listing->getAllFeatures();
$somethingelse = $this->Listing->getAllTypes();

Too many people get stuck on the idea that a model maps 1 class to 1 table when a model is really meant to be the representation of a real-world object (person, car, property, etc) in code. So the question you should be asking is what am I trying to model? Once you've decided what object you're modeling, then you code up a model that gets/sets all the properties of that object. That's not to say you can't do it the way you want to but make those decisions on how it conceptually fits with what you're coding.

El Forum

[eluser]kevinprince[/eluser]
OK, there is nothing wrong with having long structured function names in your code. It makes long term support much much easier as you can actually remember what something does.

Im also not sure why you would need to rename your tables to be the same as your functions. In theory your property is a an object of data created from several tables in your model.

If you want tidy front end urls for your users, take a look at the routes documentation

What I would advise you do is figure out what you need to display, and design models and logic to match.

El Forum

[eluser]jaswinder_rana[/eluser]
AH. I think that's what I was thinking. "1 class 1 table".

Now that you put it that way, 'class for object which will include sub-objects to THAT object', it makes more sense.

Although different classes still tempt me as I write this but I understand and will try to change my thinking.

Much appreciated.

Thanks.

El Forum

[eluser]jaswinder_rana[/eluser]
[quote author="nextgengames" date="1230868026"]OK, there is nothing wrong with having long structured function names in your code. It makes long term support much much easier as you can actually remember what something does. [/quote]

Thanks. That was the only reason I was thinking to create different class but as I mentioned before, I am trying to slowly understand things and change the way I think.

Thanks