witchy478 Posted June 28, 2012 Share Posted June 28, 2012 Hi I'm using a zend framework with wamp installed. When I try using $this->message for example I get this error: Fatal error: Using $this when not in object context in C:\wamp\www\myproject\application\views\scripts\index\index.php on line 2 How do I solve this? Thank you Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/ Share on other sites More sharing options...
Rage Posted June 28, 2012 Share Posted June 28, 2012 Hi I'm using a zend framework with wamp installed. When I try using $this->message for example I get this error: Fatal error: Using $this when not in object context in C:\wamp\www\myproject\application\views\scripts\index\index.php on line 2 How do I solve this? Thank you You are using $this-> outside of a class, $this can only be used to access things in its own class Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/#findComment-1357643 Share on other sites More sharing options...
witchy478 Posted June 28, 2012 Author Share Posted June 28, 2012 In my IndexController.php I have class IndexController extends Zend_Controller_Action { public function indexAction() { $this->view->message = 'This is my new Zend Framework project!'; } } and in my index.php I have <h1>Hello World</h1> <?php echo $this->message ?> Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/#findComment-1357647 Share on other sites More sharing options...
Rage Posted June 28, 2012 Share Posted June 28, 2012 post your entire php script so i can see more Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/#findComment-1357649 Share on other sites More sharing options...
witchy478 Posted June 28, 2012 Author Share Posted June 28, 2012 I also have layout.phtml <?php echo $this->doctype(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php echo $this->headTitle() ?> <?php echo $this->headLink() ?> <?php echo $this->headScript() ?> </head> <body> <?php echo $this->layout()->content ?> </body> </html> other then that, it's all I have for now. Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/#findComment-1357650 Share on other sites More sharing options...
scootstah Posted June 28, 2012 Share Posted June 28, 2012 I don't know much about the Zend framework but, after briefly looking at their documentation, it looks like you need to be doing other things in your controller before you can use variables in your view. Here is the two articles I was looking at: Controllers Views Link to comment https://forums.phpfreaks.com/topic/264920-this-problem/#findComment-1357653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.