Getting basepath from view in zend framework

Posted by mobmad on Stack Overflow See other posts from Stack Overflow or by mobmad
Published on 2009-03-11T18:12:06Z Indexed on 2010/03/19 19:11 UTC
Read the original article Hit count: 283

Filed under:
|

Case: you're developing a site with Zend Framework and need relative links to the folder the webapp is deployed in. I.e. mysite.com/folder online and localhost:8080 under development.

The following works nice in controllers regardless of deployed location:

$this->_helper->redirector->gotoSimple($action, $controller, $module, $params);

And the following inside a viewscript, ie. index.phtml:

<a href="<?php echo $this->url(array('controller'=>'index', 'action' => 'index'), null, true); ?>">

But how do I get the correct basepath when linking to images or stylesheets? (in a layout.phtml file, for example):

<img src='<?php echo WHAT_TO_TYPE_HERE; ?>images/logo.png' />

and

$this->headLink()->appendStylesheet( WHAT_TO_TYPE_HERE . 'css/default.css');

WHAT_TO_TYPE_HERE should be replaced with something that gives

<img src="/folder/images/logo.png />` on mysite.com and `<img src="/images/logo.png />

on localhost

© Stack Overflow or respective owner

Related posts about php

Related posts about zend-framework