2010年2月25日星期四

[fw-mvc] RE: Autodetected baseUrl not available in bootstrap?

Hi Matthew,
 
I added this resource method to my bootstrap:
 
protected function _initBaseUrl() {
        $this->bootstrap("frontController");
        $front=$this->getResource("frontController");
        $request=new Zend_Controller_Request_Http();
        $front->setRequest($request);
}

and now I have autodetected baseUrl available in the bootstrap methods. Thanks for your help!

David


________________________________

From: weierophinney [via Zend Framework Community] [mailto:[hidden email]]
Sent: Thursday, February 25, 2010 8:37 PM
To: David Lukáš
Subject: Re: Autodetected baseUrl not available in bootstrap?


-- Andy Daykin <[hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=0> > wrote
(on Thursday, 25 February 2010, 10:23 AM -0600):
> I'm having a similar problem. I'm trying to get the base url in the controller
> methods, by using:
>  
>
> Zend_Controller_Front::getInstance()->getBaseUrl();
>
> But nothing gets returned from that method. How should I get the baseUrl in a
> controller (or bootstrap for another matter - didn't mean to hijack your thread
> David).

At that point, the request is not yet initialized, and
Zend_Controller_Front::getRequest() does not lazy-load one. The simplest
way would be to simply do this:

    $request = new Zend_Controller_Request_Http();
    $front->setRequest($request);

Once you've done this, the baseUrl() view helper will have access to a
valid request object, which will give you a valid base URL.



> From: Hector Virgen
> Sent: Thursday, February 25, 2010 10:20 AM
> To: David Lukas
> Cc: [hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=1>  
> Subject: Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?
>
> I may be wrong but I believe the baseUrl is detected during the dispatching
> process, which is after all of the resources have been loaded.
>
> Are you using a layout? It would be easier to add your common CSS/JS to the
> layout script. Within the layout $this->baseUrl() should be working properly.
>
> --
> Hector
>
>
> On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <[hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=2> > wrote:
>
>
>     Hi,
>     I am intializing view placeholders in a bootstrap resource method like
>     this:
>
>     protected function _initViewPlaceholders() {
>       $this->bootstrap("frontController");
>       $front=$this->getResource("frontController");
>       $this->bootstrap('view');
>       $view = $this->getResource('view');
>
>     $view->headLink()->appendStylesheet($view->baseUrl("path/to/
>     stylesheet.css"));
>       $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
>     }
>
>     But the method does not work as expected - the style and script links have
>     no baseUrl prepended. When called from this method, $view->baseUrl() as
>     well
>     as  $front->getBaseUrl() return "/", although when called from an action
>     controller they return correctly autodetected baseUrl.
>
>     When I manually specify baseUrl in the config file:
>
>     resources.frontController.baseUrl = "/baseUrl"
>
>     the resource method works fine and files are linked correctly.
>
>     Which resource is responsible for injecting the autodetected baseUrl into
>     the front controller? Or am I missing the point completely? If yes, what is
>     the best practice for getting hold of the autodetected baseUrl in a
>     bootstrap resource method?
>
>     Thanks for any help,
>     David
>
>     ZF 1.10.1
>     --
>     View this message in context: http://n4.nabble.com/
>     Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
>     Sent from the Zend MVC mailing list archive at Nabble.com.
>
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=3>  
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc



________________________________

View message @ http://n4.nabble.com/Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1569563.html 
To start a new topic under Zend MVC, email [hidden email]
To unsubscribe from Zend MVC, click here <<Link Removed>> .



View this message in context: RE: Autodetected baseUrl not available in bootstrap?
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: