Changeset 11548
- Timestamp:
- 09/14/08 22:00:46 (2 months ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (1 diff)
- branches/1.2/lib/helper/AssetHelper.php (modified) (1 diff)
- branches/1.2/test/unit/helper/AssetHelperTest.php (modified) (2 diffs)
- doc/branches/1.2/book/09-Links-and-the-Routing-System.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11542 r11548 1124 1124 The old behavior still works without changing anything to your code. 1125 1125 1126 Image helper 1127 ------------ 1128 1129 In symfony 1.0 and 1.1 the `image_tag` helper would generate the `alt` 1130 attribute of the img-tag from the filename. This now only happens if 1131 `sf_compat_10` is on. The new behaviour eases finding of unset alt attributes 1132 using a (x)html validator. As a bonus, there is now a `alt_title` option that 1133 will set alt and title attribute to the same value, which is useful for cross 1134 browser tooltips. 1135 1126 1136 View Configuration 1127 1137 ------------------ branches/1.2/lib/helper/AssetHelper.php
r11102 r11548 321 321 } 322 322 323 if (!isset($options['alt'])) 323 if (isset($options['alt_title'])) 324 { 325 //set as alt and title but do not overwrite explicitly set 326 if(!isset($options['alt'])) $options['alt'] = $options['alt_title']; 327 if(!isset($options['title'])) $options['title'] = $options['alt_title']; 328 unset($options['alt_title']); 329 } 330 331 if (!isset($options['alt']) && sfConfig::get('sf_compat_10')) 324 332 { 325 333 $path_pos = strrpos($source, '/'); branches/1.2/test/unit/helper/AssetHelperTest.php
r9335 r11548 16 16 require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); 17 17 18 $t = new lime_test(5 4, new lime_output_color());18 $t = new lime_test(57, new lime_output_color()); 19 19 20 20 class myRequest … … 59 59 $t->is(_compute_public_path('foo?foo=bar', 'css', 'css'), '/css/foo.css?foo=bar', '_compute_public_path() takes into account query strings'); 60 60 61 $compatMode = sfConfig::get('sf_compat_10'); 62 sfConfig::set('sf_compat_10', false); 61 63 // image_tag() 62 64 $t->diag('image_tag()'); 63 65 $t->is(image_tag(''), '', 'image_tag() returns nothing when called without arguments'); 64 $t->is(image_tag('test'), '<img src="/images/test.png" alt="Test"/>', 'image_tag() takes an image name as its first argument');65 $t->is(image_tag('test.png'), '<img src="/images/test.png" alt="Test"/>', 'image_tag() can take an image name with an extension');66 $t->is(image_tag('/images/test.png'), '<img src="/images/test.png" alt="Test"/>', 'image_tag() can take an absolute image path');67 $t->is(image_tag('/images/test'), '<img src="/images/test.png" alt="Test"/>', 'image_tag() can take an absolute image path without extension');68 $t->is(image_tag('test.jpg'), '<img src="/images/test.jpg" alt="Test"/>', 'image_tag() can take an image name with an extension');66 $t->is(image_tag('test'), '<img src="/images/test.png" />', 'image_tag() takes an image name as its first argument'); 67 $t->is(image_tag('test.png'), '<img src="/images/test.png" />', 'image_tag() can take an image name with an extension'); 68 $t->is(image_tag('/images/test.png'), '<img src="/images/test.png" />', 'image_tag() can take an absolute image path'); 69 $t->is(image_tag('/images/test'), '<img src="/images/test.png" />', 'image_tag() can take an absolute image path without extension'); 70 $t->is(image_tag('test.jpg'), '<img src="/images/test.jpg" />', 'image_tag() can take an image name with an extension'); 69 71 $t->is(image_tag('test', array('alt' => 'Foo')), '<img alt="Foo" src="/images/test.png" />', 'image_tag() takes an array of options as its second argument to override alt'); 70 $t->is(image_tag('test', array('size' => '10x10')), '<img src="/images/test.png" alt="Test" height="10" width="10" />', 'image_tag() takes a size option'); 71 $t->is(image_tag('test', array('absolute' => true)), '<img src="http://localhost/images/test.png" alt="Test" />', 'image_tag() can take an absolute parameter'); 72 $t->is(image_tag('test', array('class' => 'bar')), '<img class="bar" src="/images/test.png" alt="Test" />', 'image_tag() takes whatever option you want'); 72 $t->is(image_tag('test', array('size' => '10x10')), '<img src="/images/test.png" height="10" width="10" />', 'image_tag() takes a size option'); 73 $t->is(image_tag('test', array('absolute' => true)), '<img src="http://localhost/images/test.png" />', 'image_tag() can take an absolute parameter'); 74 $t->is(image_tag('test', array('class' => 'bar')), '<img class="bar" src="/images/test.png" />', 'image_tag() takes whatever option you want'); 75 $t->is(image_tag('test', array('alt_title' => 'Foo')), '<img src="/images/test.png" alt="Foo" title="Foo" />', 'image_tag() takes an array of options as its second argument to create alt and title'); 76 $t->is(image_tag('test', array('alt_title' => 'Foo', 'title' => 'Bar')), '<img title="Bar" src="/images/test.png" alt="Foo" />', 'image_tag() takes an array of options as its second argument to create alt and title'); 77 sfConfig::set('sf_compat_10', true); 78 $t->is(image_tag('test'), '<img src="/images/test.png" alt="Test" />', 'image_tag() creates alt attribute from filename if sf_compat_10 is on'); 79 80 sfConfig::set('sf_compat_10', $compatMode); 73 81 74 82 // stylesheet_tag() doc/branches/1.2/book/09-Links-and-the-Routing-System.txt
r11181 r11548 345 345 >Chapter 7 introduced the asset helpers `image_tag()`, `stylesheet_tag()`, and `javascript_include_ tag()`, which allow you to include an image, a style sheet, or a JavaScript file in the response. The paths to such assets are not processed by the routing system, because they link to resources that are actually located under the public web directory. 346 346 > 347 >You don't need to mention a file extension for an asset. Symfony automatically adds `.png`, `.js`, or `.css` to an image, JavaScript, or style sheet helper call. Also, symfony will automatically look for those assets in the `web/images/`, `web/js/`, and `web/css/` directories. Of course, if you want to include a specific file format or a file from a specific location, just use the full file name or the full file path as an argument. And don't bother to specify an `alt` attribute if your media file has an explicit name, since symfony will determine it for you. 347 >You don't need to mention a file extension for an asset. Symfony automatically adds `.png`, `.js`, or `.css` to an image, JavaScript, or style sheet helper call. Also, symfony will automatically look for those assets in the `web/images/`, `web/js/`, and `web/css/` directories. Of course, if you want to include a specific file format or a file from a specific location, just use the full file name or the full file path as an argument. 348 >And don't bother to specify both an `alt` and `title` attribute, as `alt_title` will set both attributes to the same value, which is useful for cross browser tooltips. Note that as of symfony 1.2 the `alt` attribute is no longer autoguessed from the filename to ease finding missing tags using a validator (to enable this again, turn `sf_compat_10` on). 348 349 > 349 350 > [php] 350 > <?php echo image_tag('test' ) ?>351 > <?php echo image_tag('test.gif' ) ?>352 > <?php echo image_tag('/my_images/test.gif' ) ?>351 > <?php echo image_tag('test', 'alt=Test') ?> 352 > <?php echo image_tag('test.gif', 'title=Test') ?> 353 > <?php echo image_tag('/my_images/test.gif', 'alt_title=Test') ?> 353 354 > => <img href="/images/test.png" alt="Test" /> 354 > <img href="/images/test.gif" alt="Test" />355 > <img href="/my_images/test.gif" alt="Test" />355 > <img href="/images/test.gif" title="Test" /> 356 > <img href="/my_images/test.gif" alt="Test" title="Test" /> 356 357 > 357 358 >To fix the size of an image, use the `size` attribute. It expects a width and a height in pixels, separated by an `x`. … … 359 360 > [php] 360 361 > <?php echo image_tag('test', 'size=100x20')) ?> 361 > => <img href="/images/test.png" alt="Test"width="100" height="20"/>362 > => <img href="/images/test.png" width="100" height="20"/> 362 363 > 363 364 >If you want the asset inclusion to be done in the `<head>` section (for JavaScript files and style sheets), you should use the `use_stylesheet()` and `use_javascript()` helpers in your templates, instead of the `_tag()` versions in the layout. They add the asset to the response, and these assets are included before the `</head>` tag is sent to the browser.