1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect3 id="zend.view.helpers.initial.baseurl">
<title>BaseUrl Helper</title>
<para>
While most <acronym>URL</acronym>s generated by the framework have the base
<acronym>URL</acronym> prepended automatically, developers will need to prepend the
base <acronym>URL</acronym> to their own <acronym>URL</acronym>s in order for paths
to resources to be correct.
</para>
<para>
Usage of the BaseUrl helper is very straightforward:
</para>
<programlisting language="php"><![CDATA[
/*
* The following assume that the base URL of the page/application is "/mypage".
*/
/*
* Prints:
* <base href="/mypage/" />
*/
<base href="<?php echo $this->baseUrl(); ?>" />
/*
* Prints:
* <link rel="stylesheet" type="text/css" href="/mypage/css/base.css" />
*/
<link rel="stylesheet" type="text/css"
href="<?php echo $this->baseUrl('css/base.css'); ?>" />
]]></programlisting>
<note>
<para>
For simplicity's sake, we strip out the entry <acronym>PHP</acronym> file (e.g.,
"<filename>index.php</filename>") from the base <acronym>URL</acronym> that was
contained in <classname>Zend_Controller</classname>. However, in some situations
this may cause a problem. If one occurs, use
<methodname>$this->getHelper('BaseUrl')->setBaseUrl()</methodname> to set your
own BaseUrl.
</para>
</note>
</sect3>
|