Re: How to insert a file in a class?
| From: | sertcetin at itu dot edu dot tr | Date: | Fri, 01 Jun 2012 12:59:50 +0000 |
| Subject: | Re: How to insert a file in a class? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318072@lists.php.net to get a copy of this message | ||
file_get_contents() ?
--
Ege Sertçetin
Alinti LAMP <lamp@afan.net>
Hi to all. Let's say there is a class class Box { var $box_title; var $box_content; function __construct() { $this->box = ''; } function box_title($title) { $this->title = $title; } function box_content($content) { $this->content = $content; } function make_box() { $this->box = '<h3>'.$this->box_title.'</h3>'.$this->box_content; } function get_box() { return $this->box; } } $box = new Box(); $box->box_title('PHP Classes'); $box->box_content('Starting with PHP 5, the object model was rewritten to allow for better performance and more features. This was a major change from PHP 4. PHP 5 has a full object model.') $box->make_box(); echo $box->get_box(); This works fine. The problem I have is how to "include" a file as box_content? it could be plain text, but it could be a form or some kind of code. $box->box_include(include(/path/to/file/file.php)) doesn't work, of course. Wrapping up the whole code in a variable doesn't make a sense too: # file.php $content = ' <form method="post" action="$_SERVER['PHP_SELF']"> Email = <input type=text name=email> Pass = <input type=password name=pass> <input type=submit value=Submit> </form>'; # main.php $box = new Box(); $box->box_title('PHP Classes'); include(file.php); $box->box_content($content); $box->make_box(); echo $box->get_box(); Also, I'm sure I read once it's not correct to print directly from a class. First return a value/result to "main" code and then print. Correct? LAMP