Guest Posted November 26, 2013 Share Posted November 26, 2013 I have created a class to build up the content in my page. I want to use this a broad as possible. Where I run into, is how to enclose certain content within (for example) a div, without the need for calling a closing tag. Below is a section of my class, which does the following: __construct -> Creates the "<article>" section (closed when ->Display() is called). This to keep each section in their own <article> tag AddHeader -> creates the header within the <article> AddContent -> creates the div in which all the content should be kept. Display -> closes the <div> and </article> and allows it to be echo'd. What I don't want is to keep calling the AddContent for every piece of content, but would like to add the content via various options like 'AddGraph', 'AddTable', which will be added to the content section. Also besides the header, potential tabs could be added, so adding the <div> after the header tag is not an option. Any good suggestions and/or source which would help me further? With kind regards Ralf <?php class PageContent { var $content; function __construct($class= NULL) { $this->content = "\n<article". (!empty($class) ? " class='". $class ."'" : "") .">\n"; //$this->content = "\n<div". (!empty($class) ? ' class=\"$class\"' : '') .">\n"; } function AddHeader($naam, $class= NULL){ $this->content .= "<header><h3". (!empty($class) ? " class='". $class ."'" : "") .">". $naam ."</h3></header>\n"; } function AddContent($class= NULL){ $this->content .= "<div". (!empty($class) ? " class='". $class ."'" : "") .">\n"; } function Display() { $this->content .= "<div class='clear'></div>\n"; $this->content .= "</div>\n"; $this->content .= "</article>\n"; return $this->content; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284291-php-class-to-include-content-in-div/ Share on other sites More sharing options...
cyberRobot Posted November 26, 2013 Share Posted November 26, 2013 (edited) Instead of calling the AddContent method directly, the AddGraph method could perform the call. Side note: some of the basics for creating classes in PHP have changed. For example, "var" is no longer required. More information can be found here: http://php.net/manual/en/language.oop5.php If you declare a property using var instead of one of public, protected, or private, then PHP 5 will treat the property as if it had been declared as public. Edited November 26, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284291-php-class-to-include-content-in-div/#findComment-1460164 Share on other sites More sharing options...
Guest Posted November 26, 2013 Share Posted November 26, 2013 Thanks for the suggestion, but when I call the function from the AddGraph function, it will still need a closing tag or won't be able to add another piece of information, like the Addtable to the same div. Or do you see this different?With kind regards Ralf Quote Link to comment https://forums.phpfreaks.com/topic/284291-php-class-to-include-content-in-div/#findComment-1460166 Share on other sites More sharing options...
cyberRobot Posted November 26, 2013 Share Posted November 26, 2013 Once AddGraph has done it's thing, it could call another method to close the tag. Quote Link to comment https://forums.phpfreaks.com/topic/284291-php-class-to-include-content-in-div/#findComment-1460168 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.