Jump to content

Recommended Posts

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?

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.

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

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.

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.

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.

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

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.