$sf_response->addStyleSheet() dosen't work in SF 1.4?

独自空忆成欢 提交于 2019-12-02 07:27:15

Edit:

Ok I think I got it now. You should add include_stylesheets() into the head section of your layout file:

<html>
   <head>
       <title>This is the title</title>
       <?php include_stylesheets() ?>
   </head>
   <body>
   <!-- ... -->

Then in your template file, you use use_stylesheet() to add a particular stylesheet for this template:

<?php use_stylesheet('/path/to/stylesheet.css') ?>

From the API documentation:

include_stylesheets()
Prints <link> tags for all stylesheets configured in view.yml or added to the response object.

use_stylesheet()
Adds a stylesheet to the response object.

Same for Javascript.


According to the API documentation it should still work in 1.4, sfWebResponse still has this method:

addStylesheet ($file, $position, $options)   
  $file   The stylesheet file  
  $position   Position   
  $options    Stylesheet options  
Adds a stylesheet to the current web response.

At least the method exists.
What exactly is the problem? Do you get an error if you want to call that method or is the stylesheet just not added?

http://www.symfony-project.org/tutorial/1_4/en/upgrade#removal_of_the_common_filter

As of 1.4 your javascripts and stylesheets are no longer automatically injected into your head tag. Instead, you need to include the following in your layout where you'd like them to be placed:

<?php include_javascripts() ?>
<?php include_stylesheets() ?>

and just in case your post title wasn't a typo you'll want to use addStylesheet('...') off of the response:

$sf_response->addStylesheet('main');

$sf_context->getResponse()->addStylesheet('style.css')

$sf_context->getResponse()->addJavascript('script.js')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!