1

I have this JS function that's use a ZF2 helper to get the URL of my application:

        function siteUrl(route){
            var url = '<?php echo $this->url();?>';
            if(route != null && route != ''){
                url = url + route;
            }
            return url;
        }

And it's return for me a address like this '/Program/MyProgramModule/public/index.php/controller' (notice that my application is not running in a Virtual Host).

But I want to get only the address without the Controller. I need it because I will make requests for another controller or module.

Thank!!

Lazaro Henrique
  • 527
  • 5
  • 7
  • Is there a reason you can't use the regular zf2 routing? `$this->url( 'login/process', array( 'action' => 'authenticate' )` – Kevin Ard Sep 10 '15 at 00:13
  • If not that, would javascript's `window.location.href` not work for you? [see this post](http://stackoverflow.com/questions/1034621/get-current-url-in-web-browser) – Kevin Ard Sep 10 '15 at 00:17
  • You can not set it in JS file, but you can set all of your routes in .phtml file as global JS vars. And later use it in JS files/code. – tasmaniski Sep 10 '15 at 07:43
  • @kevinard I can't use it because because I need to pass the controller and the action as JS string, not PHP. The idea of `windows.location.href` is good, but i think it's will not work because my application could be running in a virtual host or not, i could have have a `mod_rewrite` or not. Thx by the way – Lazaro Henrique Sep 10 '15 at 11:32
  • @tasmaniski It's already in phtml file, the layout file, so I can call it in every place of my application. Thx by the way – Lazaro Henrique Sep 10 '15 at 11:33
  • I solved it creating a ViewHelper to get the URLs that I will need in my application from the global config file. Thank's everyone! – Lazaro Henrique Sep 10 '15 at 14:21

0 Answers0