1

UPDATE:

Turns out it's not only the routing, but any instance of going 'up' a directory.

For example mysite.com/public serves me the correct index.phtml file... mysite.com/index/testpage DOES serve me the testpage.phtml, but my directory structure is completely screwed and I lose all links to images & Stylesheets etc. I've checked my .htaccess and it's exactly as recommended.

Serious head-scratching time here...

OP:

Hello..

I'm using this method for catching urls and serving up the correct content

$router->addRoute(
    'list',
    new Zend_Controller_Router_Route('/list', array('controller'=>'index', 'action'=> 'list'))
    );

And it works really well, serves up the content from list.phtml...

but, the moment I attempt anything 'up' a directory such as this I lose all my style sheets and other relative scripts.

$router->addRoute(
    'listWithUsers',
    new Zend_Controller_Router_Route('/list/:users', array('controller'=>'index', 'action'=> 'list'))
    );

It's strange because I can access the users variable and echo it to screen, it's just that I lose all scripts and stylesheets whenever a URL contains /

For clarity, I'm able to set actions in the indexController.php to catch URLS and it works, but it seems to serve it as another directory causing me to lose all relative links.

Thanks for any help. Please advise if any specific details would help.

1 Answer 1

2

For any kind of MVC app using routes like this, you have to specify absolute path for your resources. This will prevent the issue you have.

For example, if I have a website located at mysite.com/app1 and I have a resource located in lib/jquery-1.2.6.min.js, then a valid path will be /app1/lib/jquery-1.2.6.min.js.

For this I have always used some kind of helper to return the site's base URL in my views.

<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/lib/jquery-1.2.6.min.js"></script>

You can use a view helper or a constant.

Sign up to request clarification or add additional context in comments.

1 Comment

This works. Many thanks for your help. I was aware of the need for absolute paths, but was following along with Zend Screencasts and there were no absolute paths used. Either way my Application is working now. Thanks. For archives sake - echo $this->baseUrl() worked for me, not echo $this->getBaseUrl()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.