Re: How to insert a file in a class?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jun 1, 2012, at 7:46 AM, David OBrien wrote:



On Fri, Jun 1, 2012 at 8:41 AM, LAMP <lamp@xxxxxxxx> 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"


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux