Seperating the view from the logic

So the company I currently work at has a custom build framework. One of the most irritating thing regarding this framework is how tightly bound the business logic is with the view.

I want to separate these. I am thus looking for a very basic template engine to integrate as I am pushed on time and cant custom develop something. I am looking for an engine that handles variables very similar to how Zend handles them in their views.

I am not interested in learning new syntax. A template engine which I can use to pass variables across will be sufficient.

Here is how I would like to see it be used:


$view->categories = array('category 1', 'category 2', 'category 3'); // thisshould allow me to accees categories in the view as a php array.

definitely a worthwhile goal. I don’t think a template system on its own will help. You need to manually remove the HTML from the models.

What I’d do is: leave it as it is until you need to change something, at this point separate out the HTML (you should just be able to copy/paste the method) include the file and replace $this with $model or whatever.

The current problem is that the model classes are slandered with html code. This makes the code exceptionally difficult to read and maintain.

I want to seperate the html code from the php business logic. I do not mind using php in the html files, but only to correctly display/format the data.

Doesn’t sound like you want a template engine. How is the data currently accessed in the view?

A template system may help but be wary, binding logic like that can lead to repeated code and maintainability problems.

If I’m not generating markup in the method itself (when generating tables from data for example) then I generally use output buffering inside the method to capture the template with it’s variable content and return it as a string. Makes it easier to slice and dice the final layout.

to borrow a regex related quote:
first you have a problem using php variables in your html.
So you start using a templating engine.
Now you have two problems…