1
votes

Zend Framework is totally new for me, and I have problem with it. Probably it's easy to fix, but I can't find any solution in Google.

I can't figure out how to set correct path to public folder. Im using xampp as virtualhost, my current full path looks like this:

localhost/zf_project/public/controller/action

Now, when I'm using forms and links it moves me to localhost/controller/action, so currently I'm adding everywhere:

$front = Zend_Controller_Front::getInstance();  
$form->setAction($front->getBaseUrl().'/controller/action');

Probably there is simplest way to set default path to public folder. I tried add in my .ini application file:

resources.frontController.baseurl = "/zf_project/public"
2

2 Answers

4
votes

ZF can determine your base URL without having to set it in your config file or from the bootstrap.

From views, you can construct links with the base URL using the baseUrl helper.

// resolves to localhost/zf_project/public/controller/action
$this->form->setAction($this->baseUrl('controller/action'));

// or

// resolves to localhost/zf_project/public/images/icons/online.png
<img src="<?php echo $this->baseUrl('images/icons/online.png') ?>" />

You can construct URLs using the url helper. This constructs your URLs based on the routes configured.

// localhost/zf_project/public/controller/action/id/1234
echo $this->url(array('controller' => 'controller',
                      'action'     => 'action',
                      'module'     => 'default', 
                      'id'         => 1234));

You can use either of these helpers from your controllers too, just specify the view object when you want to call them:

$this->view->baseUrl();
$this->view->url($params);

Pretty much anywhere I reference images, javascripts, css files, or static content I use the baseUrl helper. Any time I want to link to other controllers or actions within my application, I use the url helper since it constructs valid URLs using your routes. That way if you change your URL structure, the url helper will reflect the changes and you don't have to modify your existing code.

2
votes

You need to modify your virtual host file.

It is standard practice to have Zend applications on base root.

In your XAMP (I am not much of Windows but, will give a try), you should have a folder as : /xampp/apache2/conf there you will find apache2.conf or httpd.conf, either of them. Open them, you should find DocumentRoot somewhere, navigate that with your /public folder.

Alternatively, make a new virtual host altogether.

Also, I found this good tutorial, follow it step by step (or jump over to step 3)

Hope it helps :)

Questions?