How to add an external javascript file to a Zend Framework 2 application?

后端 未结 7 2203
梦毁少年i
梦毁少年i 2021-02-07 14:42

I need to add jQuery and other javascript files to my Zend Framework project. I am trying to do it with an Action controller:-

public function userinfoAction()
{         


        
相关标签:
7条回答
  • 2021-02-07 15:41

    you can try this. its works fine for me

    //write these lines in your SampleController

    public function someAction()
    {
    
    $this->getViewHelper('HeadScript')->appendFile('/js/yourjsfile.js');
    $this->getViewHelper('HeadScript')->appendFile('/js/jquery/jquery.min.js');
    }
    

    // write following method in controller

    protected function getViewHelper($helperName)
    {
    
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
    }
    
    0 讨论(0)
提交回复
热议问题