Giovanni A. D. wrote:

> - having the website not on the web root (on my local apache I've it
> like /test/zend/my_test/test01/ ...)
>
> - having the library folder outside my project (just make a symbolic
> link or better to change config files?)
>
> I've found this message:
> http://www.nabble.com/forum/ViewPost.jtp?post=11117463&framed=y
>
> that suggests to define a/use the "BASE_PATH" constant.. and this
> should answer to my first question.. but is not clear to me if this is
> the best method and if yes, I wonder why this is not used / showed in
> the quickstart tutorial..
>
> and also.. from my test with the guestbook example I've changed the
> _getGuestbookForm method adding:
>
> $base =$this->getRequest()->getBaseUrl();
> $form->setAction($base.$this->_helper->url('sign'));
>
> ..cause else it didn't worked correctly if it was on a subdirectory..
>
> so which one is the best to use? getBaseUrl() or
> BASE_PATH.$this->_helper->url('sign') or .. ?
>
> and how do you handle this usually inside views?
> I've also thought to use the html base tag in the header but not sure
> that is the best method..
>


Due to my hosting provider, I'm in a similar situation.

In my views, I use the Zend_View_Helper_Url as much as possible, since it
automatically figures out the base url:

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


When including links to my /public folder, I've made a view helper which
does essentially what you described with the $request->getBaseUrl():

class App_View_Helper_BaseUrl extends Zend_View_Helper_Abstract
{
    public function baseUrl($add_path = '')
    {
        $front = Zend_Controller_Front::getInstance();
        return rtrim($front->getBaseUrl(), '/') . '/' . ltrim($add_path,
'/');
    }
}

...Using it like so:

<img src="<? echo $this->baseUrl('/public/img/PoweredBy_ZF_4LightBG.png');
?>" border="0">


In my controller actions, I use the Redirector action helper when I
redirect:

$this->_helper->Redirector->setCode(303)
            ->gotoSimple("index", "user", "admin", array());


For $form->setAction() and other types of url setup within the action
controllers, I just use the view helper that I mentioned already:

$form->setAction($this->view->url(array('module'=>'admin',
'controller'=>'user', 'action'=>'index'), null, true));


Giovanni A. D. wrote:

> Also in that example there is a forms folder with the form code..
> which are the best practices to handle that kind of things? Is that
> (having a form folder) the best one or which one do you like the most?
>


I put my Form classes within my library folder so it can be easily found by
the autoloader.
ex. $form = new App_Form_Login(); // -> lib/App/Form/Login.php

Hope this helps.

Reply via email to