0

I want to split a unique javascript file to get a file by action. On my controllers I use jQuery()->addJavascriptFile() to call js files :

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

In my public/js folder I got a folder by controller and a js file by action... It works well only with the indexAction, for all of the others the name of the controller is inserted into the URI : With indexAction : http://192.168.78.208/demande_absence/public/js/demandes/index.js With any other : http://192.168.78.208/demande_absence/demandes/public/js/demandes/nouvelle.js

What I've done wrong ?

2 Answers 2

1

Try:

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

And i think you also have to use something like the baseurl view helper to build a correct url.

Sign up to request clarification or add additional context in comments.

2 Comments

baseUrl is a view helper. How can i use this in controller ?
@SiCK $this->view->baseUrl...
0

Maybe because it's not an absolute path. Try this:

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

1 Comment

I prefer use the view->baseUrl() because the paths of dev and prod servs are differents

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.