这里使用了Unobtrusive Flash Objects (UFO). ,下载后使用里面的ufo.js放到你的js目录里,把flash(.swf)文件放到swf目录下。在lib/helper目录里创建一个FlashHelper.php文件。
FlashHelper.php

  1. <?php
  2.  /**
  3.   * Flash object helper - embeds Flash objects (files with the .swf extension)
  4.   *
  5.   * Uses Unobtrusive Flash Objects (UFO)
  6.   *
  7.   * @param string $id - The ID od the div which will be replaced by flash movie
  8.   * @param mixed  $options - Flash object options
  9.   * @see http://www.bobbyvandersluis.com/ufo/
  10.   */
  11. function flash_object($id, $options = array())
  12. { 
  13.   sfContext::getInstance()->getResponse()->addJavascript('ufo.js');
  14.  
  15.   $options = _parse_attributes($options);
  16.   $absolute = false;
  17.   if (isset($options['absolute']))
  18.   {
  19.     unset($options['absolute']);
  20.     $absolute = true;
  21.   } 
  22.   if(isset($options['size']))
  23.   {
  24.     list($options['width'], $options['height']) = split('x', $options['size'], 2);
  25.     unset($options['size']);
  26.   }
  27.   if(!isset($options['majorversion'])) 
  28.   {
  29.     $options['majorversion'] = 7;
  30.   } 
  31.   if(!isset($options['build'])) 
  32.   {
  33.     $options['build'] = 0;
  34.   } 
  35.   // check for all required params 
  36.   foreach(array('movie', 'width', 'height', 'majorversion', 'build') as $required)
  37.   {
  38.     if(!isset($options[$required]))
  39.     {
  40.       throw new sfException("{FlashHelper} Required parameter \"$required\" is missing.");
  41.     }
  42.   }              
  43.   $options['movie'] = flash_path($options['movie'], $absolute)
  44.   $opts = array();
  45.   foreach ($options as $key => $value)
  46.   {
  47.     $opts[] = $key . ': "' . $value . '"';
  48.   }
  49.   sort($opts);
  50.   // javascript variable name
  51.   $name = $id . '_var'
  52.   $js = 'var ' . $name . " = {".join(', ', $opts)."};\n";  
  53.   $js .= 'UFO.create('.$name.', "'.$id.'");'."\n";  
  54.   return content_tag('script', "\n//".cdata_section("\n$js\n//")."\n", array('type' => 'text/javascript'));
  55. }
  56.  
  57.  /**
  58. * Returns the path to a flash swf movie.
  59. *
  60. * <b>Example:</b>
  61. * <code>
  62. *  echo flash_path('mymovie');
  63. *    => /swf/mymovie.swf
  64. * </code>
  65. *
  66. * <b>Note:</b> The asset name can be supplied as a...
  67. * - full path, like "/swf/movie.swf"
  68. * - file name, like "movie.swf", that gets expanded to "/swf/movie.swf"
  69. * - file name without extension, like "movie", that gets expanded to "/swf/movie.css"
  70. *
  71. * @param string asset name
  72. * @param bool return absolute path ?
  73. * @return string file path to the flash movie file
  74. */
  75. function flash_path($source, $absolute = false)
  76. {
  77.   return _compute_public_path($source, 'swf', 'swf', $absolute);
  78. }

在模版里的调用方法如下:

  1. <div id="flashcontent">
  2.   This text is replaced by the Flash movie.
  3. </div>
  4. <?php use_helper('Flash'); ?>
  5. <?php echo flash_object('flashcontent', array(
  6.   'movie'=>'movie.swf',
  7.   'width'=>'200',
  8.   'height'=>'300',
  9.   'bgcolor'=> '#FFFFFF');
  10. ?>

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2011 刘敏的Blog Suffusion theme by Sayontan Sinha