BZero Posted April 28, 2010 Share Posted April 28, 2010 I'm just starting to learn OOP and frameworks, and I read this (http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf) Zend framework tutorial, and it uses "$this" all over the place. Isn't "$this" supposed to be used inside classes to refer to the class it's in? If you, for example, go to the bottom of page 12 in that tutorial, "$this" is used right at the beginning of a new file. Is that entire .phtml file somehow inside a class? I'm confused... Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/ Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 Simplest way to check what $this is, is to var_dump($this); AFAIR in this case it's an instance of Zend_View, and a view script are executed in its context. Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050007 Share on other sites More sharing options...
BZero Posted April 28, 2010 Author Share Posted April 28, 2010 So all of index.phtml is inside the Zend_View class? How? Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050077 Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 /** * Includes the view script in a scope with only public $this variables. * * @param string The view script to execute. */ protected function _run() { if ($this->_useViewStream && $this->useStreamWrapper()) { include 'zend.view://' . func_get_arg(0); } else { include func_get_arg(0); } } Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050080 Share on other sites More sharing options...
BZero Posted April 28, 2010 Author Share Posted April 28, 2010 OK, so if I make a new .phtml file in views/scripts/{controller name}/ and use "$this" in that file, that would automatically refer to the Zend_View class, without me having to do anything else to make it that way? Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050117 Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 Assuming you configured a view in your controller Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050126 Share on other sites More sharing options...
BZero Posted April 28, 2010 Author Share Posted April 28, 2010 But that's done automatically by ViewRenderer, right? From the tutorial: "Zend Framework provides an Action Helper for us called the ViewRenderer. This takes care of initialising a view property in the controller($this->view) for us[...]" Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050162 Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 I believe that's the case in current version of ZF. I think in the past you had to create a View explicitly. Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050169 Share on other sites More sharing options...
BZero Posted April 28, 2010 Author Share Posted April 28, 2010 Yeah. I just googled "ViewRenderer" and found this announcement from its developer, from 2007: http://devzone.zend.com/article/2072 Anyway, thanks for your help, man. This has cleared up my confusion a bit. I don't have any more questions right now, but I'll go find some more tutorials, and then I'll undoubtedly be back with more questions later. Quote Link to comment https://forums.phpfreaks.com/topic/200057-this-outside-classes-someone-explain/#findComment-1050181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.