This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | PHP code completion does not detect Zend Framework method "url()". | ||
---|---|---|---|
Product: | php | Reporter: | eklutna |
Component: | Zend | Assignee: | Petr Pisl <ppisl> |
Status: | NEW --- | ||
Severity: | normal | CC: | sohorev, tmysik |
Priority: | P3 | ||
Version: | 6.x | ||
Hardware: | PC | ||
OS: | Linux | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Attachments: | Screen shot of failed code completion. |
I have checked Zend_View_Interface class in the library/Zend/View directory and the function url() isn't there so the code completion works correctly from this point of view. Could you please specify what the function url() should do? Where is a source code for it in the Zend framework? Using grep, I found 4 instances of functions named "url" in the Zend Framework version 1.10.8. The one I'm concerned about is #3 below. The code and comments are posted below for your convenience, or you can go to the file path listed in #3. #1 ZendFramework-1.10.8/library/Zend/Controller/Action/Helper/Url.php: public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) #2 ZendFramework-1.10.8/library/Zend/View/Helper/Navigation/Sitemap.php: public function url(Zend_Navigation_Page $page) #3 ZendFramework-1.10.8/library/Zend/View/Helper/Url.php: public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true) #4 ZendFramework-1.10.8/tests/Zend/Navigation/_files/My/UrlHelper.php: public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) * Helper for making easy links and getting urls that depend on the routes and router * * @package Zend_View * @subpackage Helper * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_View_Helper_Url extends Zend_View_Helper_Abstract { /** * Generates an url given the name of a route. * * @access public * * @param array $urlOptions Options passed to the assemble method of the Route object. * @param mixed $name The name of a Route to use. If null it will use the current Route * @param bool $reset Whether or not to reset the route defaults with those provided * @return string Url for the link href attribute. */ public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true) { $router = Zend_Controller_Front::getInstance()->getRouter(); return $router->assemble($urlOptions, $name, $reset, $encode); } } IMHO this is more enhancement than a bug because $view variable is Zend_View_Interface implementation and this interface does not have any url() method (as Petr already wrote). I guess it is a helper function (likely called via magic method __call()?). If I'm wrong, please, correct me. Thanks. In any case, it would be good to have a look at the official ZF documentation. Yes, url() is a helper function which is available via registering (method addHelperPath() is used for it) in Zend_View_Abstract. The problem is that the view helper main functions (the ones named for the helper class) are made available to the view via __call(). Further, in a .phtml file NetBeans has no idea that $this is a Zend_View since no class is declared. To assist my team I created an interface (HGM_View) and copied into it the method declarations of the most common Zend view helpers as well as our own. class HGM_View { /** * Retrieve rendered contents of a controller action * ... */ public function action($action, $controller, $module = null, array $params = array()); ... rest of view helper main methods ... } By adding <?php /* @var $this HGM_View */ ?> as the first line of every view script, we now have code completion for view helpers. It's not ideal as we need to update the interface whenever we add new helpers, but it works. Now, if only I could register the [ .phtml -> $this is-a HGM_View ] association with NetBeans so we don't have to include that line in every script... Batch reassigning. Editor area, we need more flexible/extensible editor part. |
Created attachment 102326 [details] Screen shot of failed code completion. While attempting to create a link to another page by using Zend Framwork's method "url()", I noticed that NetBeans PHP code completion does not detect the method, even though it is usable in the context of a /views/scripts/index/index.phtml file. // At this point, code completion does pop up, but method "url()" is not listed. <a href="<?php echo $this-> // I can manually type the rest of the code, and this does work, so method "url()" was valid in this context, but not picked up by code completion. <a href="<?php echo $this->url(array(), 'Page2'); ?>">Page 2</a> Zend Framework Version: 1.10.8