0

我想拆分一个唯一的 javascript 文件以通过操作获取文件。在我的控制器上,我使用 jQuery()->addJavascriptFile() 来调用 js 文件:

class DemandesController extends Zend_Controller_Action
{ 
  public function init()
  {
    $this->view->jQuery()->addJavascriptFile('public/js/' . $this->getRequest()->getControllerName() . '/' . $this->getRequest()->getActionName() . '.js');
  }
}

在我的 public/js 文件夹中,我通过控制器获得了一个文件夹,并通过操作获得了一个 js 文件......它仅适用于 indexAction,对于所有其他人,控制器的名称都插入到 URI 中:使用 indexAction:http: //192.168.78.208/demande_absence/public/js/demandes/index.js 与任何其他:http : //192.168.78.208/demande_absence/demandes/public/js/demandes/nouvelle.js

我做错了什么?

4

2 回答 2

1

尝试:

 $this->view->jQuery()->addJavascriptFile('/public/js/' . $this->getRequest()->getControllerName() . '/' . $this->getRequest()->getActionName() . '.js');

而且我认为您还必须使用诸如 baseurl 视图助手之类的东西来构建正确的 url。

于 2012-02-09T16:14:56.623 回答
0

也许是因为它不是一条绝对路径。尝试这个:

$this->view->jQuery()->addJavascriptFile('/public/js/' . $this->getRequest()->getControllerName() . '/' . $this->getRequest()->getActionName() . '.js');
于 2012-02-09T16:16:39.343 回答