2010年2月25日星期四

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

-- Andy Daykin <daykinandy@gmail.com> 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: fw-mvc@lists.zend.com
> 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 <david.lukas@langfor.cz> 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 | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: