+ Reply to Thread
Results 1 to 2 of 2

Thread: getUrl not prepending appropiate URL

  1. #1
    TheZend is offline Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Default getUrl not prepending appropiate URL

    Hey, not sure where to ask this question, but...

    I'm trying to use the following function to prefix Url's dynamically within my application, both for use in Smarty templates and in breadcrumbs, etc:

    Code:
    public function getUrl($action = null, $controller = null)
            {
                $url  = rtrim($this->getRequest()->getBaseUrl(), '/') . '/';
                $url .= $this->_helper->url->simple($action, $controller);
    
                return $url;
            }
    I'm also using a Smarty pluggin, which contains basically the same function listed here above, to output the Url's using: {geturl controller='events'} or {geturl controller='account' action='logout'}, etc. The smarty class looks like this:

    Code:
    <?php
        function smarty_function_geturl($params, $smarty)
        {
            $action     = isset($params['action']) ? $params['action'] : null;
            $controller = isset($params['controller']) ? $params['controller'] : null;
    
            $helper = Zend_Controller_Action_HelperBroker::getStaticHelper('url');
    
            $request = Zend_Controller_Front::getInstance()->getRequest();
    
            $url  = rtrim($request->getBaseUrl(), '/') . '/';
            $url .= $helper->simple($action, $controller);
    
            return $url;
        }
    ?>
    I'm not sure how or why, sometimes it outputs correctly, but often is doesn't and the Url will be:

    http://events/

    Etc...

    I'm using a virtual host to locate my root directory, maybe this has something to do with it?

    But given the output http://events/, it seems like the call to getBaseUrl() isn't returning correctly...any ideas?

  2. #2
    Stonepost is offline Junior Member
    Join Date
    Feb 2010
    Posts
    3

    Post Smarty, Zend, PHP, and Apache walked into a bar...

    I am experiencing the same issue....
    System Setup:
    Ubuntu 9.10
    Apache 2.2.14
    PHP5
    Smarty 2.6.26
    Zend Framework Minimal 1.9.6


    I am actually able to get my URL to populate:
    i.e.
    "http://www.domain.com/account"
    "http://www.domain.com/account/register"
    "http://www.domain.com/account/fetchpassword"

    However unable to get to the page, just getting 404 - page not found error when selecting links. The controller AccountController.php is
    located in ./include/Controllers/.

    Not sure if it is an Apache re-write issue but my code is the same as TheZend's code. (must be using Apress - Practical Web 2.0 Applications with PHP)

    my .htaccess is as follows:

    Code:
    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule^(.*)$ index.php/$1

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 02-25-2009, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts