blueman378 Posted February 13, 2009 Share Posted February 13, 2009 hi guys, im looking to make some templateable sites, the thing is how is the best way to seperate the business logic from the design? i dont want to use a template engine which you basically have to learn a new language for eg smarty. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/ Share on other sites More sharing options...
Q695 Posted February 13, 2009 Share Posted February 13, 2009 Are you talking about something like this: http://www.sd52gop.com/ If your answer is yes, do an include with a switch statement on several levels depending on what you need. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761077 Share on other sites More sharing options...
blueman378 Posted February 13, 2009 Author Share Posted February 13, 2009 i honestly have no idea what that site has to do with my question.... but basically im asking is different functions the best way to go to separate the logic from the design. eg something like index.php would contain all the functions required eg, one to display a random text message from the data base then at the bottom have an include which includes eg index.phpd (phpdesign) which will be compiresed of all the html, and as an example instead of having the code to get the news somewhere in there instead it owuld jsut be <?php news(); ?> that way it can be used on multiple templates obviously, but is there a tidier way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761105 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Share Posted February 13, 2009 Do include pages with case statements, and call all the globals at the top of index.php. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761134 Share on other sites More sharing options...
blueman378 Posted February 13, 2009 Author Share Posted February 13, 2009 heh i get that, infact ive got that a step futher, (mod rewriting) but thats not my question, although thanks for the suggestion, basically the idea is have you ever used smarty? with it all your php is in one file, the other file is the design, in the first file there is not a single line of html. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761156 Share on other sites More sharing options...
RichardRotterdam Posted February 13, 2009 Share Posted February 13, 2009 hi guys, im looking to make some templateable sites, the thing is how is the best way to seperate the business logic from the design? i dont want to use a template engine which you basically have to learn a new language for eg smarty. The easiest way is probably a template engine like you already mentioned. Then you could also have php output xml and use xslt to style the data. And if you want to really seperate everything all the way go MVC using a framework like ZendFramework,symphony or cakePHP Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761157 Share on other sites More sharing options...
gethinw Posted February 13, 2009 Share Posted February 13, 2009 The easiest way is probably a template engine like you already mentioned. Then you could also have php output xml and use xslt to style the data. Ugh, the thought of that still makes me shiver, from back when I hadn't discovered frameworks and thought that it would be a good way to work. Do yourself a favour and learn a framework, I use Zend Framework, which is very nice to use once you get your head around it. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761163 Share on other sites More sharing options...
Prismatic Posted February 13, 2009 Share Posted February 13, 2009 Smarty is not hard at all. You put all your templates in the templates folder. inside each template where you want a variable to show do {$variable_name} then you simply do $smarty = new Smarty(); $smarty->assign("variable_name", "Hello world!"); $smarty->display("template_file.html"); It can be more complicated if you'd like but all template engines will follow the same general flow. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761172 Share on other sites More sharing options...
blueman378 Posted February 13, 2009 Author Share Posted February 13, 2009 ive been doing some research in MVC but still cant really get my head around its concept... Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761183 Share on other sites More sharing options...
RichardRotterdam Posted February 13, 2009 Share Posted February 13, 2009 It can be quite intimidating at first when you start using an MVC design patern. But once you get used to working with one of the frameworks eventually you'll get it. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761213 Share on other sites More sharing options...
nadeemshafi9 Posted February 13, 2009 Share Posted February 13, 2009 i create model clases for interacting with each table of teh db include config include required classes, include functions, instantiate all my controlling is then done at the top of each page for postbacks include js and all the view is at the bottom you can have separate views as view.inc.php files and separate controller pages that using js switch views in the above pages called adaptors with included view pages when using AJAX, you need to create your own concept. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761232 Share on other sites More sharing options...
nadeemshafi9 Posted February 13, 2009 Share Posted February 13, 2009 MVC model view controler you have a model = the way your app is gona talk to the DB view is teh html and that controler is when you post back to teh page or get post etc using javascript, javascript then further complexfies it as it is a controller and view manipulator which you have to accept to be all in one. so if i click submit what happens next is called the controller. javascript you use to manipulate your view which has been outputted it uses the controller wich is activated when you press something the controller uses the model to access the DB or whatever functions etc classes all of these things can be functions classes or whatever and use javascript or wotever wich further compolexifies it lol MVC is for system programs we carry it forward as it eases web app complexity. Web apps are more complex then system apps Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761235 Share on other sites More sharing options...
blueman378 Posted February 13, 2009 Author Share Posted February 13, 2009 cheers guys. Quote Link to comment https://forums.phpfreaks.com/topic/145035-solved-seperating-logic-from-design/#findComment-761696 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.