1 Replies - 7867 Views - Last Post: 27 June 2013 - 07:27 PM

#1 SirHenrik  Icon User is offline

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 31
  • Joined: 31-December 10

How to incorporate OOP in a PHP MVC framework

Posted 23 March 2013 - 04:48 AM

I want to start making proper objects in PHP, and up until now my only exposure to classes have been controllers, models and views in frameworks such as CodeIgniter. So far I have viewed controllers as a kind of 'site structural' thing, mostly due to that they are accessible from the URL (at least in CodeIgniter).

Example:
If I wanted to create a blog I would probably make these two controllers.
  • Post controller, for viewing blog posts
  • Admin controller, for login and administrative stuff

But if you imagine viewing a page with a blog post in it it will have several objects. Firstly there is the actual post-object which holds the content of the post, and then there could be a comment object, if you have a comment section. A comment object could inherit from a people object. Maybe if the blogpost where to be a photo album, instead of the traditional text, the post object would inherit from a photoalbum object.

I see all these objects which fits into the post-section of the site, but I have no clue where to put them. Should I make them inside the controller? How would I then go about using that object another place? Or should I write them to a library, include the library and then initiate them when I need them in the controller I am working in?

What is the proper way of doing this? Since up until now I have only typed procedural code within the methods of the controllers I make.

Any input on this case would be appreciative.

Is This A Good Question/Topic? 0
  • +

Replies To: How to incorporate OOP in a PHP MVC framework

#2 FusionNinja  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 13

Re: How to incorporate OOP in a PHP MVC framework

Posted 27 June 2013 - 07:27 PM

Essentially you will create them in your library and then init them in your controllers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1