Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

set property with HTML content as string in from include not possible

property include

Best Answer LDDbyD, 03 October 2018 - 05:59 AM

Ok, after a big time of research, analyzing every step of the code I found what is the problem:

- it's a simple misunderstood of POO inheritance: I was trying to set the property "buffer" of the parent from child.

 

The solution:

- I use now a property in the child class named "buffer" and get it from the parent class using getter function from child.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 LDDbyD

LDDbyD

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 01 October 2018 - 06:33 AM

Hi, 

it has been a long time I didn't came here, it's good to code again!

 

What I wanna do:

- include the content of a file at a specific moment in a method's class and set it in a property's class

 

What it means in real:

- 1 I call function giveMeView in SessionController class -> this one ask the child SessionView class to get HTML and set it in property buffer

class SessionController{

    public $buffer;

    public function giveMeView($what){
        $view = new SessionView();
        switch (strtolower($what)){
            case 'login_form':
                $view->loginHtmlInBuffer();
                echo $this->getBuffer();
                break;
        }
    }

    /**
     * GET&SET
     */
    public function getBuffer(){
        return $this->buffer;
    }
    public function setBuffer($buffer){
        $this->buffer = $buffer;
    }

- 2 in SessionView child extended to SessionController parent, it require login form and call returnBuffer function from it and set content in buffer property

class SessionView extends SessionController{

    public function loginHtmlInBuffer(){
        require_once './login_form.phtml';
        $this->setBuffer(strval(returnBuffer())); //I tried to call it without strval() = same result
    }

}

- 3 in the login_form.phtml it return HTML content

function returnBuffer()
{
    return '
    <html>
        <head>
            <!-- ... -->
        </head>
        <body id="LoginForm">
            Hello
        </body>
    </html>';
}

What is the problem:

- if I set returned value in property buffer (what I would like to do), nothing is displayed!

- But when I use echo function without set content in property, display of HTML is perfect

 

What I tried:

- echo function at every step (works)

- return function without any function in login_form.phtml (works)

- use of global variable (re-declaring it in the method's class) (works)

- use of local variable (works)

- use of property's class (sucks)

- take a break  :) (no change)

 

How it is now:

- return direct HTML string

- use it as a local variable

 

Anyone see or know where is the bug? I'm searching the web from many hours now and I feel lost...

 

Thanks for the time and answers!


Edited by LDDbyD, 01 October 2018 - 06:36 AM.


#2 LDDbyD

LDDbyD

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 03 October 2018 - 05:59 AM   Best Answer

Ok, after a big time of research, analyzing every step of the code I found what is the problem:

- it's a simple misunderstood of POO inheritance: I was trying to set the property "buffer" of the parent from child.

 

The solution:

- I use now a property in the child class named "buffer" and get it from the parent class using getter function from child.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download