2008年8月21日星期四

Re: [fw-mvc] question about view script

I've been trying to come up with a good answer for this myself. I have scripts and stylesheets that are included on every page, but only when using my default layout. To accomplish this, I have a rather large block of php code at the top of my layout view script like this:

<?php

$this->headLink()->prependStylesheet('/css/old-realtown/supplemental.css');
$this->headLink()->prependStylesheet('/css/old-realtown/main.css');
$this->headLink()->appendStylesheet('/css/old-realtown/ie.css', 'screen', 'IE');

$this->headScript()->prependFile('/js/common.js');
$this->headScript()->prependFile('/js/cookies/cookies.js');
$this->headScript()->prependFile('/js/scriptaculous/scriptaculous.js');
$this->headScript()->prependFile('/js/prototype/prototype.js');

?>


It's a little awkward, but it's the only way I have found to ensure that the base scripts and layout-specific stylesheets are loaded for this layout only. Also note that I have to do some strange juggling of prepend* and append* to ensure the files are loaded in the right order. This is especially true for me because I tend to append view-specific stylesheets and javascript files at the controller level (which is added to the placeholders before the layout adds its files).

-Hector


Jigal sanders wrote:
What would be the best way to have all the initial values of these helpers on one place?
I don't want to set the same values in each controller. How can i solve this in a nice way?

On Thu, Aug 21, 2008 at 3:31 PM, Емил Иванов / Emil Ivanov <emil.vladev@gmail.com> wrote:
Using scriptHead is a solution.

But I think your problem is with the variable setting:

> But when i say in my controller:
>
> $this->script = "event.js";
>
> then it doesn't work.

This should be $this->view->script = "event.js";

Regards


--
My place to share my ideas:
http://vladev.blogspot.com



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489

没有评论: