NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Type Hint for view scripts


Joined: 02 Aug 2007
Posts: 12
Location: Hamburg Germany
Reply with quote
I am using Zend Framework and there is no code completition inside view scripts. I know that IDE has no knowledge of the properties and I have to type hint.
I am doing somethig like this:
Code:

<?php
/** @var Zend_View */
$this;
/** @var My_Model_Page */
$page = $this->page;
?>
<?php
$this->
$page->
?>

It would be much better if I could do this:
Code:

<?php
/**
* @var Zend_View $this The Zend View Object
* @var My_Model_Page $this->page My Page Object
*/
?>
<?php
$this->
$this->page->
?>

Or am I missing something??

KASI
View user's profileFind all posts by kasiSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
May I ask you to post more or less complete example? Perhaps a kind of trivial case with two files would be enough.

Regarding $this, it's almost never requires type-hints because its type is current class and it's always known (unless I don't understand what's going on).
Regarding $this->page, you may want to add type hint to the place where "page" property is declared. In this case all references to page will be recognized properly.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 02 Aug 2007
Posts: 12
Location: Hamburg Germany
Reply with quote
A view script is a plain php script that is included by a method of a class.
Basically like this:
Code:

class Zend_View {
   
    public function render($script){
        /*
        $this->page  is a Page Object set somewhere else
        */
        return include $script;  // /some/path/to/template.phtml
    }
}


and /some/path/to/template.phtml like:
Code:

<h1><?php echo $this->page->getTitle() ?></h1>
<p><?php echo $this->page->getContent() ?></p>

So when editing the template PhpED can not know of what type $this is or which properties it has.
So I need type hinting.

KASI
View user's profileFind all posts by kasiSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
What I should say... This kind of code is not supported. If possible, please don't include files into a class method or function.
Otherwise, you have to provide typehint for $this too.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 12 Sep 2006
Posts: 11
Reply with quote
This is the way Zend Framework's MVC works (or can work) - the view file is a separate phtml file which is basically a Zend_View instance (Zend/OO purists will correct me here no doubt - hey I used to code in 68000, all this OO stuff isn't my bag)

It would be a great help if there was a way of explicitly typing a whole file to a particular class, perhaps a preference where you could say that a .phtml is essentially a Zend_View class (link it with the class file).

Sorry I think that was really badly explained!
View user's profileFind all posts by ifloSend private message
Type Hint for view scripts
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic