Welcome Guest, Not a member yet? Register   Sign In
Object Oriented Design Patterns with CodeIgniter
#1

[eluser]peterbz[/eluser]
Before I start writing my CMS, I want to plan out everything. To be honest, my OO concepts are a bit rusty as I am somewhat new to it and have trouble applying good design patterns.

So here's my problem.

I am writing a car CMS and as you know, many different categories and inner pages are somewhat similar. Is there a way to "extend" from a parent controller or model so that pages such as used cars, auto parts, etc can inherit from the similar structure?

I came across this page on the forum:
http://ellislab.com/forums/viewthread/100641/

but I don't quite understand why he would write a "module" to extend for his blogs, forums, and polls if most of the things are written in controllers and models.
#2

[eluser]Mackstar[/eluser]
Yes I wouldn't worry about modules for now, until you know that you need them.

As for your car website, the kind of workings that you are hoping for is exactly what CI does best, you can create models for your cars, car parts then use the controllers to inject that data into your pages as needed.

I would also look at keeping the actions in your controllers limited to certain actions so they don't get too long and complicated. I like rails and its restful approach which tries to limit your controller actions to add, show, list, create, destroy, update and edit.

I have found keeping stuff simple in such a manner help so much with keeping my code maintainable.

Where possible keep all data processing actions in the model. Keeping the fat model, skinny controller approach. (Modules can be used to stop your controllers getting bloated!)

Cheers

Richard
#3

[eluser]peterbz[/eluser]
Can you provide under what circumstances I will need modules.
#4

[eluser]Mackstar[/eluser]
OK the particular post you were relating to is not referring to what I would call modules (I would call modules more like the kind of extensibility used by libraries in CI).

The article was more talking about creating a base controller class of which many similar general actions can be extended into whatever specific controller you are using.

For example in your case where cars and parts may use a similar type of pages you could make make a function in the base class called detail and have the same base function control both parts and cars details pages.

But you would need to build it well to make sure that you pulled out the correct data based on the controller that was calling the base class. A bit of knowledge of php OO functions will help.

Cheers

Richard
#5

[eluser]peterbz[/eluser]
Also, I was wondering if I should split auto parts and cars and wheels into separate tables since they all have different attributes. Or should I create an attribute table and put all auto parts, cars, wheels into 1 table.
#6

[eluser]Mackstar[/eluser]
I would probably split them up, then have a parts, cars and wheels model, but that is how my brain works...

Cheers

Richard
#7

[eluser]peterbz[/eluser]
Is it possible for me to create a controller called Listings and have 2 other controllers (CarListings and PartsListing) extend the Listings controller?
#8

[eluser]Mackstar[/eluser]
Yes it is, create the base controller in MY_Controller.php in libraries and then extend it from there...

Thanks

Richard
#9

[eluser]Daniel Peraza[/eluser]
There are a lot of interesting stuff in Software Engineering that comes along with OOP Design Patterns.

Use case modeling is a basic step in all software engineering processes. Starting from that point, might allow you to identify classes (controllers, models or libraries) and design patterns that could apply to your CMS development project.

Despite this is not an answer to your question, strictly speaking, I'd really recommend you to apply this concepts to your project because it offers an invaluable opportunity to build a plan to develop your software, and to focus on the most important problems you'd want to solve.

Also, if you follow a special software engineering development methodology as Agile, XP, Scrum, RAD, etc... you may also find interesting things such as software development costs estimations (e.g. by using COCOMO), risk management (things that could stop your development project), etc.

Although you may not have the time enough to put this concepts in practice, or you'd rather focus on getting results quickly, if you follow these standard practices, you sure will get the big picture of what your CMS is going to be up to the last detail. And you sure get the benefits of using industry standard proven software development methodologies.

Good luck!.




Theme © iAndrew 2016 - Forum software by © MyBB