Jump to content

Recommended Posts

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. :P

Link to comment
https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/
Share on other sites

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');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835360
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835372
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835373
Share on other sites

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. :P

 

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.

Link to comment
https://forums.phpfreaks.com/topic/158389-procedural-based-mvc/#findComment-835380
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.