hukadeeze Posted May 15, 2007 Share Posted May 15, 2007 I'm learning to use OOP, and I'm having trouble getting a template to work. My architecture is set-up like this: - Application Class - Class that set settings - Class that controls session variables - Class with the applications control logic. Every request the application class loads the other 3. The logic class is a series of switch statements. Before the switch statements I load a class which I've called master template with the method 'display'. It is a header, 2 column, footer layout. In the right column I echo a variable called $maincontent. Within each switch are all the instructions to handle a specific request, like executing a query, organizing the results, building dynamic menus, ect. I'm running into trouble displaying the content. I've created a different class for every page to be displayed. For example, I have a class called ProductsDisplay with the methods product_contents(). I call the the display class from inside it's respective switch. class Logic{ //Load Template include (mastertemplate.php); $display = new MasterTemplate; //Inside Request Specific Switch include (query.php); include (products.php); $query = new Query(); $queryresults = $query -> product_query(); $products = new ProductsDisplay; $display -> maincontent = $products -> product_contents($queryresults); //Display $display -> Display(parameters); } I'm having trouble returning content from the display classes. I'm using the return function. I don't have problems when I use only html, but I cannot use php inside the return function. class ProductsDisplay{ function product_contents($queryresults){ return 'html and php markup to output query'; <---this returns all markup as regular text. return require (htmlandphpmarkupincludefile.php); <----this executes correctly, but the results are displayed before the rest of the template. } } How can I return the contents of an executed script from a child class to a parent class? Link to comment https://forums.phpfreaks.com/topic/51414-solved-templates-in-oop/ Share on other sites More sharing options...
hukadeeze Posted May 15, 2007 Author Share Posted May 15, 2007 I answered my own question. I used the combo assign operator to add everything I needed to one variable and then returned the variable. ... $var .= '<p>'.$title.'</p><br />'; $var .= '<p>'.$description.'</p><br />'; .... return $var; Link to comment https://forums.phpfreaks.com/topic/51414-solved-templates-in-oop/#findComment-253246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.