Welcome Guest, Not a member yet? Register   Sign In
rookie problem
#1

[eluser]mortifrog[/eluser]
Hi, I've been using PHP quite successfully for a number of years but am new to OO and programming with any sort of framework. I think if I can crack this CI methodology, I will be on fire, but so far I'm just managing the odd spark!

Can someone tell what's wrong with the following code please?

Code:
class Welcome extends Controller {
    
var $content;

    function Welcome()
    {
        parent::Controller();
            
        $this->content='q_content';
        
    }
    
    function index()
    {
        echo $this->content; # this works
        $this->load->view('q_page_open');
          $this->load->view($this->$content); # this doesn't - why?
        $this->load->view('q_page_close');
    }
}

CI gives me an error of: Undefined variable: content

and PHP chucks up - Cannot access empty property in ....

It seems to me as if I have defined a property named q_page and am asking to load it's contents as a view? I know I must be being dim, but I'm too dim on this occasion to work out why!
#2

[eluser]xwero[/eluser]
$ too much
#3

[eluser]mortifrog[/eluser]
Doh! thanks! The crazy thing is I didn't spot the difference between my two examples. 0/10 for observation!
#4

[eluser]xwero[/eluser]
always check for typos first, it is the most common cause of bugs Smile
#5

[eluser]Colin Williams[/eluser]
It also helps to have a good IDE. Mine would flag that with the warning "The local variable $content may not have been initialized"
#6

[eluser]mortifrog[/eluser]
It was a complete howler and I feel suitably embarrased for posting it! I always do check for typos - but sometimes, you can't see the wood for the trees when you're a little stressed!

I'm not keen to change my editor just yet though as I've only just dicovered it and apart from not picking up that typo, it seems to be the best PHP editor I've ever used - it's phpDesigner - unless you can tell me something that's better. ( I used to use Homesite, and I still use Dreamweaver for some stuff)




Theme © iAndrew 2016 - Forum software by © MyBB