Man*_*ghe 13 javascript jquery zend-framework zend-framework2
我需要将jQuery和其他javascript文件添加到我的Zend Framework项目中.我正在尝试使用Action控制器: -
public function userinfoAction()
{
$this->view->headScript()->appendFile($basePath .'/js/validate_jquary.js');
$this->headScript()->appendFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
return new ViewModel();
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.
aim*_*eld 10
以下是如何在ZF2中的控制器中使用视图助手来解决您的问题:
public function someAction()
{
$this->getViewHelper('HeadScript')->appendFile($basePath . '/js/somejs.js');
}
protected function getViewHelper($helperName)
{
return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
}
Run Code Online (Sandbox Code Playgroud)
$this->HeadScript()->appendFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js','text/javascript');
$this->HeadScript()->appendFile('http://localhost/zend/public/js/validate_jquary.js','text/javascript');
Run Code Online (Sandbox Code Playgroud)
在视图中使用此代码即可.但我不知道这是正确的方法.
| 归档时间: |
|
| 查看次数: |
20465 次 |
| 最近记录: |