NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[Code Insight] Type hinting not working in phtml?


Joined: 10 Feb 2018
Posts: 1
Reply with quote
Hi,
in my project I use phtml files as templete which is included into controller. I try declare $this variable type just like in example for cakePHP (www.nusphere.com/php/cakephp5.htm), but this doesn't working. Code competition works fine when I try use $this-> right after docblock comment, but later in document I got only error message. Can anyone help?

I used PhpED 17.

Thank's for any response.
View user's profileFind all posts by MarthasNSend private message
Guru master

Joined: 24 Jul 2009
Posts: 729
Reply with quote
I cannot test in v17 because I am using v18. However, I just opened a large phtml template and did a test on that with $this showing correct code completion all the way to the bottom of the file.

Because phtml files are outside of a class context and PhpED cannot work out the class, I define $this before the first usage:

Code:
<?php
/**
* @var Mage_Catalog_Block_Product_List $this
*/
$_productCollection = $this->getLoadedProductCollection(); // code completion until end of file
?>
<?php
$_productCollection = $this->getLoadedProductCollection(); // this second PHP block also gets code completion
?>


It is important you use the variable after defining it, possibly it needs to be in the same PHP block. If you do not, then PhpED does appear to 'forget' it.

This does NOT work for me and this appears to be effectively what the cakephp5 example does, using two separate code blocks:

Code:
<?php
/**
* @var Mage_Catalog_Block_Product_List $this
*/
?>
<?php
$_productCollection=$this->getLoadedProductCollection(); // does not get code completion
?>
View user's profileFind all posts by plugnplaySend private message
[Code Insight] Type hinting not working in phtml?
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