How write JavaScript with Zend Framework and netbeans?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 01:44:56

问题


I am writing JavaScript like that:

<?php $this->headScript()->captureStart();?>
$(function(){
    // some javascript magic
});
<?php $this->headScript()->captureEnd(); ?>

But problem is that it is not highlighted and there is no autocomplete... I have tried write like this:

<?php $this->headScript()->captureStart();?>
//<script>
$(function(){
    // some javascript magic
});
<?php $this->headScript()->captureEnd(); ?>

Now it is highlighted but netbeans is not happy about not closed <script> tag and some other issues with Zend... Then after some more googling found this:

<?php if( false ) {?><script><?php } ?>
$(function(){
    // some javascript magic
});
<?php if( false ) { ?></script><?php } ?>

Works fine but maybe there is better solution for this?


回答1:


You can extend HeadScript, this is simplest solution:

class My_View_Helper_HeadScript extends Zend_View_Helper_HeadScript
{
    public function captureEnd()
    {
        $content = ob_get_contents();
        ob_clean();
        echo strip_tags($content, 'script');

        parent::captureEnd();
    }
}

Specify helper path:

resources.view.helperPath.My_View_Helper = "My/View/Helper"

Usage:

<?php $this->headScript()->captureStart();?>
    <script>
      alert(1);
    </script>  
<?php $this->headScript()->captureEnd(); ?>



回答2:


Write your js in external JS files.

It will allow for better separation, better caching, better aggregation, better highlighting, etc.

Here are some links that may help you:

  • Managing CSS/JS with Zend
  • Managing CSS/JS with Zend (another point of view)
  • Setting the javascript build path (for auto completion and stuff like this)


来源:https://stackoverflow.com/questions/10311281/how-write-javascript-with-zend-framework-and-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!