• Pingback: Zend Framework base url | PHP-Blog.com()

  • Pingback: CSS not applying correctly in ZendFramework - Zend Framework Forum()

  • You don’t need to…The helper works out the box πŸ˜›

  • Brutuscat

    I can’t make the setBaseUrl to work, so I improved the baseurl method like this:

    This will find the first occurrence of the ‘index.php’ and remove everything after it leaving the baseurl only.


  • Luciano

    ZF 1.9.2 have Zend_View_Helper_BaseUrl

    but it doesn’t work, why?

  • Can you rephrase that? Did you try my helper and it didn’t work? I didn’t tested it in ZF 1.9.2, but it should work…

  • I see a BaseUrl helper in ZF, but it doesn’t work.
    So I googled the web finding this and other post talking about a BaseUrl helper.
    My question is why the default helper doesn’t work.

    I ask this question here because Your post almost recent.

    Your Helper too doesn’t work if I don’t use ‘/beta’ subdir (see belowe)
    the Lensselink’s one work in my case. (but not as I like)

    My bootstrap:

    My helper:

    My View calls to the helper:

    looking at my helper you see two vars: $base_url and $file.
    only $file is returned, $base_url return always empty if I use ‘/’ in setBaseUrl().

    If I try ‘/subdir’ in setBaseUrl() it works!

    If I use ‘/’ the output is:
    on a page like http://localhost/resource

    on a page like http://localhost/resource/

    the Lensselink’s one render as belowe:

    no one render ‘http://localhost/’ as I wish

  • I took the liberty of altering your comment and adding the proper markup. You can use <pre lang=”php”> code </pre> . I don’t know why the default helper doesn’t work, as I haven’t used the 1.9.2 version of the framework yet.

    My helper was posted here on the 31st of January 2009, so it’s fairly old. It simply returns the base url as it’s encapsulated in the FrontController object.

    You must understand that the front controller doesn’t keep any record about the domain your site is running on. For instance, my baseUrl() will return the path part of the url (see this page for details).

    The domain the application is running at a given time shouldn’t be relevant to the application itself. But if really want your domain to be returned by the baseUrl() helper, you have to parse the data from the $_SERVER superglobal. You can find an useful example here.

    Was this useful?

  • thanks for the tips about the path.

    anyway the helpers (neither yours or the zend one) seems to work, this can be helpfull for other people looking for it.

    thanks again

  • Since I’ve used my helper without any problems in several projects that are now live and Zend Framework’s components are thoroughly tested prior to their release, I’m inclined to believe that you’ve made a mistake somewhere in your application.

    They may not work in the way that you want them to work – returning the whole URL with the domain name. With this, I agree. But again, they shouldn’t. An application should be domain independent.

    Best of luck in finding a component suitable for you. And,.after you do, perhaps you’ll find the time to post it here, so it will be helpful to others…

  • The Zend helper should work out of the box with a simple one liner —

    baseUrl(‘blah’) ?>

    Assuming you’ve set the baseUrl up in your config file of course —

    resources.frontController.baseUrl = “http://example.com:7000/”

  • I am just starting out with Zend Framework. My boss wants me to learn everything about it. That is why I came across your site. I will bookmark your site in case I need more help. I know I still have to read a lot from your site.

Advertisment ad adsense adlogger