Re: [PHP] How to insert a file in a class?
file_get_contents() ? -- Ege Sertçetin Alinti LAMP l...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to insert a file in a class?
On Jun 1, 2012, at 8:00 AM, Gibbs wrote: On 01/06/12 13:41, LAMP wrote: 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 Couldn't you just do something like: function box_content($file = NULL) { $content = file_exists($file) ? include($file) : NULL; $this-content = $content; } It really depends what is being included (text, HTML, PHP etc). Personally I would create a different method for each different type as they will have to be treated and returned differently. Gibbs No. It doesn't work. And yes, the content of the box could be anything. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to insert a file in a class?
On Jun 1, 2012, at 7:46 AM, David OBrien wrote: On Fri, Jun 1, 2012 at 8:41 AM, LAMP l...@afan.net wrote: 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 file_get_contents I still can get the content of a file?!? echo file_get_contents($content); doesn't show anything. though, echo htmlspecialchars(file_get_content($content)); will show the code. means it is there
Re: [PHP] How to insert a file in a class?
LAMP l...@afan.net hat am 1. Juni 2012 um 14:41 geschrieben: include(file.php); $box-box_content($content); $box-make_box(); echo $box-get_box(); Wrong approach. Right is: $content = file_get_contents('file.php'); $box-box_content($content); Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to insert a file in a class?
On Jun 1, 2012, at 8:11 AM, LAMP wrote: On Jun 1, 2012, at 7:46 AM, David OBrien wrote: On Fri, Jun 1, 2012 at 8:41 AM, LAMP l...@afan.net wrote: 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 file_get_contents I still can get the content of a file?!? echo file_get_contents($content); doesn't show anything. though, echo htmlspecialchars(file_get_content($content)); will show the code. means it is there Works perfect! Me dummy, forgot I had style=display: none; within the dive tag :) :) :) Thanks to all for help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php