Jump to content

Recommended Posts

One problem I see happening when using an MVC pattern is that I will have controllers that are very large.  For instance I have a site that has a community so if i were to convert this to MVC community would become a controller class and each page would be become a method.  The problem is that there are 15-20 files the perform certain function, that is a lot of methods and it is not like the logic for these function are small.  This file could possible become over 10,000 lines long.  Is there a way certain MVC Frameworks handle this issue? 

 

One way i was thinking that i don't know how to do is basically a reserve extend on the controllers class.  This was brought up when some said make each method a separate file and i don't want to do that because i would then be using class operators/variables(parent::, $this->, etc...) in a file that is not a class and that is bad programming practice.  The next idea was each method is it own class but then i will be calling a separate class and function every time and that would be a little hard to manage.  That lead me to think if there was only a way to do a reserve extend, i would then create a class for each page and then have the main controller(like in this case, community) inherit all of those classes method.

Link to comment
https://forums.phpfreaks.com/topic/91287-handle-pages-with-mvc/
Share on other sites

You're definitely doing something wrong if you get 10,000 line long controllers.

 

Example:

/user/login = UserController::loginAction()

/user/register = UserController::registerAction()

/news/read/189 = NewsController::readAction()

/news/post = NewsController::postAction()

/news/edit/846 = NewsController::editAction()

(you don't have to use those naming conventions though)

Link to comment
https://forums.phpfreaks.com/topic/91287-handle-pages-with-mvc/#findComment-467875
Share on other sites

well I would have at least 20 methods(pages) for the user community section

 

user_community::index()

user_community::trip_information();

user_community::search();

user_community::profile();

etc.... i am not going to name them all

 

now if i have 20 method is would have to be 500 lines per method for 10,000 but it would easily be in the 4000+ range.  Another issue beside file size in multiple people working on a file.  I mean here we have up to 4 people working and if they are all work in the user community but different pages(but still same files) even with SVN, things can get messed up, that is another reason to separate each method into it own class to keep file size down and help with people editing same file at the same time.

Link to comment
https://forums.phpfreaks.com/topic/91287-handle-pages-with-mvc/#findComment-467898
Share on other sites

You need to break user_community down into smaller parts by the looks.

 

As for this...

 

I mean here we have up to 4 people working and if they are all work in the user community but different pages(but still same files) even with SVN, things can get messed up, that is another reason to separate each method into it own class to keep file size down and help with people editing same file at the same time.

 

The Linux kernel has litterally thousands of developers, and many could be working on the same piece of code at the same time without issue. This all comes down to management.

 

Besides which, the user_community part of your application should not really be a part of your framework at all, but a completely seperate project built with the framework.

Link to comment
https://forums.phpfreaks.com/topic/91287-handle-pages-with-mvc/#findComment-468763
Share on other sites

You need to break user_community down into smaller parts by the looks.

Besides which, the user_community part of your application should not really be a part of your framework at all, but a completely seperate project built with the framework.

 

Well all the part of the user_community belong there and yes the entire website is separate from the framework, I know that.

 

I think i have a solution for that problem tho, not sure if it is the best.  I will basicallt have by base controller class have functionality in the __call method so that is i call $user_community->home it loads $user_community_home->index or $user_community->profile calls $user_community_profile->index and so on.

Link to comment
https://forums.phpfreaks.com/topic/91287-handle-pages-with-mvc/#findComment-468796
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.