开发者

How to add styles dynamically from layout folder of zend application

My all styles are located behind the root under application layout folder. I don't want to keep my styleS in public folder.

How can I read them dynamically in my lay开发者_如何学运维out using below commands?

$styleFile = "greenish.css"; // from database
$this->headLink()->appendStylesheet(APPLICATION_PATH . 'modules/frontManagement/layouts/styles/'.$styleFile);

Any Idea?


If you want to avoid inline styling and only use headlink() but deliver content that is tucked safely away outside the web root or in a db, then it sounds like you'll have to headLink() to a dynamic server-side script that accepts the customer identifier and then delivers that customer-specific CSS, complete with mime-type headers.

With clever cache headers and url naming, you might even be able to get this to cache on the browser side, like you'd get with static, totally public CSS resources.

But I'll tell ya, it all sounds like overkill to me. Who cares if all the other styles are 'accessible' as long as you deliver only stylesheet_XXX.css to customer 'XXX'? Still, if it's your requirement, then I think you can manage it with the approach above.


Why wouldn't you want to keep your styles/scripts in the public folder? That's where you're supposed to keep them because, well, because their public resources.

Even if you kept them somewhere else, you'd still have to read it and apply the styles to your page. Which means you can't actually hide it (if that's your intention)


I think you want the HeadStyle view helper which includes the style sheet inline in the document head. The basic usage is something like this:

$styleFile = "greenish.css"; // from database
$style = file_get_contents(APPLICATION_PATH . 'modules/frontManagement/layouts/styles/'.$styleFile);
$this->headStyle()->appendStyle($style);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜