Prodigal Son Posted May 16, 2009 Share Posted May 16, 2009 Hi, So I've been doing some php coding here and there, but have never really layed out my code too well. I just recently read up on MVC. I have one site where I basically have all views in one folder, and one huge file of all my functions. I want to break it up so that I have a model for each view with the functions used for that view. It should be a lot easier to find things. I ran into a few problems on where to place things. If I have some common functions that are used throughout the site and could be potentially used for each and every view I should put those in a lib folder right? So common string functions and such fit well, but the problem I have is that some functions are only used in two of my views. It wouldn't make sense to copy the function into the two models that correspond to the two views. But putting the functions that are only used on two views into the lib folder that is included on every page also doesn't seem right, to me at least. Any ideas on what would be the proper place to put functions such as those? Hopefully people understand what I mean. Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/ Share on other sites More sharing options...
RussellReal Posted May 16, 2009 Share Posted May 16, 2009 classes.. are designed almost specifically for this.. and include them as you need em lol and use require_once() that way if u accidentally try to include it more than once, it doesn't throw a fatal error for example: <?php if ($whatever == 'blah') { require_once('Blah.class.php'); $blah = new Blah($whatever); echo $blah->doWhateverWedNeedToDo(); } else { require_once('Main.class.php'); $main = new Main(); $main->formPage('Template.html'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835360 Share on other sites More sharing options...
sKunKbad Posted May 16, 2009 Share Posted May 16, 2009 Not to throw a wrench in the cogs, but you could save yourself a lot of time by using a good framework like CodeIgniter or Kohana. They have the MVC all set up for you, and since you know a little about MVC, you should be able to start working immediately. You don't have to use the rest of their framework if you don't want, but I think once you see how they work you will start using them, and it will save you a lot of time. http://codeigniter.com http://kohanaphp.com Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835372 Share on other sites More sharing options...
Zhadus Posted May 16, 2009 Share Posted May 16, 2009 I'd recommend putting anything that you use more than once in a library as you never know what may use them again in the future. Also as long as you are doing some reworking, take a look at some other functions, you may be able to combine a few that do similar things. Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835373 Share on other sites More sharing options...
Prodigal Son Posted May 16, 2009 Author Share Posted May 16, 2009 classes.. are designed almost specifically for this.. and include them as you need em lol Hopefully when I get into OOP. This is still a procedural based site. I'd recommend putting anything that you use more than once in a library as you never know what may use them again in the future. Also as long as you are doing some reworking, take a look at some other functions, you may be able to combine a few that do similar things. Yea, I guess I'll just do that. In my case I don't think I'll use those functions anywhere else, but it just happens to be two views. So it just seemed kind of weird to include them for all the views, but I guess that's still better than the way I did before, which is including one big file for all views. Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835380 Share on other sites More sharing options...
Mchl Posted May 16, 2009 Share Posted May 16, 2009 MVC in general relies on object oriented code. Creating 'procedural' MVC might be tricky... Quote Link to comment https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.