在Yii上使用JavaScript(XWF / SWF图表)(Using JavaScript with Yii (XWF/SWF Charts))

编程入门 行业动态 更新时间:2024-10-28 04:28:15
在Yii上使用JavaScript(XWF / SWF图表)(Using JavaScript with Yii (XWF/SWF Charts))

我正在尝试使用Yii加载XML / SWF图表并遇到一些麻烦。 据我所知,问题似乎是Yii在标题中加载脚本标记的顺序。

这是我的工作test.php脚本(减去Yii)生成的标题所得到的源代码。

<HTML> <script language="javascript"> /*<![CDATA[*/ AC_FL_RunContent = 0; DetectFlashVer = 0; var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; /*]]>*/ </script> <script src="AC_RunActiveContent.js" language="javascript"></script> <BODY bgcolor="#FFFFFF">

现在我想让Yii使用这段代码完成同样的事情。

<?php Yii::app()->clientScript->registerScript('AC_FL_RunContent', 'AC_FL_RunContent = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('DetectFlashVer', 'DetectFlashVer = 0;', CClientScript::POS_HEAD); Yii::app()->getClientScript()->registerScriptFile($chartUrl.'/AC_RunActiveContent.js'); Yii::app()->clientScript->registerScript('DetectFlashVer', ' var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; ', CClientScript::POS_HEAD); ?>

这就是我得到的

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="language" content="en" /> <link rel="stylesheet" type="text/css" href="/css/main.css" /> <link rel="stylesheet" type="text/css" href="/css/form.css" /> <link rel="stylesheet" type="text/css" href="/css/components.css" /> <link rel="stylesheet" type="text/css" href="/css/pages.css" /> <script type="text/javascript" src="/assets/e5f807c3/AC_RunActiveContent.js"></script> <script type="text/javascript"> /<![CDATA[/ AC_FL_RunContent = 0; DetectFlashVer = 0;

var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45;

/]]>/ </script> </head> <body>

问题似乎是加载AC_RunActiveContent.js的行的位置。 当我将它移动到我的测试脚本中的其他变量之上时,它会破坏测试脚本。 有没有办法迫使Yii按我想要的顺序编写命令?

更新8/23 / 10-已解决!!!

有了Gray Teardrop的建议,我能够让这个工作。 鉴于我现在已经挣扎了几天,我以为我会为其他人发布完整的解决方案。

首先,我在protected/vendors/Maani上安装了XML / SWF图表

show.php(包含图表的视图)

<?php $chartPath=Yii::getPathOfAlias('application.vendors.Maani.*'); $chartUrl=Yii::app()->getAssetManager()->publish($chartPath);

Yii::app()->clientScript->registerScript('AC_FL_RunContent', 'AC_FL_RunContent = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('DetectFlashVer', 'DetectFlashVer = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('Morestuff', ' var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; ', CClientScript::POS_HEAD); Yii::app()->getClientScript()->registerScriptFile($chartUrl.'/AC_RunActiveContent.js',CClientScript::POS_BEGIN); ?>

<?php $chart = "<chart><chart_type>bar</chart_type><chart_border color='FF0000' /></chart>"; ?>

<script language="JavaScript" type="text/javascript"> /<![CDATA[/ if (AC_FL_RunContent == 0 || DetectFlashVer == 0) { alert("This page requires AC_RunActiveContent.js."); } else { var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); if(hasRightVersion) { AC_FL_RunContent( 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2', 'width', '400', 'height', '250', 'scale', 'noscale', 'salign', 'TL', 'bgcolor', '#777788', 'wmode', 'opaque', 'movie', 'charts', 'src', '<?php echo $chartUrl; ?>/charts', 'FlashVars', "library_path=<?php echo $chartUrl; ?>/charts_library&xml_data=<?php echo $chart; ?>", 'id', 'my_chart', 'name', 'my_chart', 'menu', 'true', 'allowFullScreen', 'true', 'allowScriptAccess','sameDomain', 'quality', 'high', 'align', 'middle', 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'play', 'true', 'devicefont', 'false' ); } else { var alternateContent = 'This content requires the Adobe Flash Player. ' + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.'; document.write(alternateContent); } } /]]>/

请注意, src和FlashVars上的相对路径信息是必需的。

I'm trying to load up XML/SWF Charts with Yii and having some troubles. As far as I can tell, the trouble seems to be the order that Yii is loading the script tags in the header.

This is what the resulting source looks like from the header generated by my working test.php script (minus Yii).

<HTML> <script language="javascript"> /*<![CDATA[*/ AC_FL_RunContent = 0; DetectFlashVer = 0; var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; /*]]>*/ </script> <script src="AC_RunActiveContent.js" language="javascript"></script> <BODY bgcolor="#FFFFFF">

Now I'm trying to get Yii to accomplish the same thing using this code.

<?php Yii::app()->clientScript->registerScript('AC_FL_RunContent', 'AC_FL_RunContent = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('DetectFlashVer', 'DetectFlashVer = 0;', CClientScript::POS_HEAD); Yii::app()->getClientScript()->registerScriptFile($chartUrl.'/AC_RunActiveContent.js'); Yii::app()->clientScript->registerScript('DetectFlashVer', ' var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; ', CClientScript::POS_HEAD); ?>

And this is what I'm getting

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="language" content="en" /> <link rel="stylesheet" type="text/css" href="/css/main.css" /> <link rel="stylesheet" type="text/css" href="/css/form.css" /> <link rel="stylesheet" type="text/css" href="/css/components.css" /> <link rel="stylesheet" type="text/css" href="/css/pages.css" /> <script type="text/javascript" src="/assets/e5f807c3/AC_RunActiveContent.js"></script> <script type="text/javascript"> /<![CDATA[/ AC_FL_RunContent = 0; DetectFlashVer = 0;

var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45;

/]]>/ </script> </head> <body>

The issue seems to be the placement of the line that loads AC_RunActiveContent.js. When I move it above the other variables in my test script it breaks the test script. Is there any way to force Yii to write the commands in the order I want them?

UPDATE 8/23/10- SOLVED!!!

With Grey Teardrop's suggestions I was able to get this working. Given I struggled with this for several days now, I thought I'd post the full solution for others.

First, I have XML/SWF charts installed at protected/vendors/Maani

show.php (view containing the chart)

<?php $chartPath=Yii::getPathOfAlias('application.vendors.Maani.*'); $chartUrl=Yii::app()->getAssetManager()->publish($chartPath);

Yii::app()->clientScript->registerScript('AC_FL_RunContent', 'AC_FL_RunContent = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('DetectFlashVer', 'DetectFlashVer = 0;', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('Morestuff', ' var requiredMajorVersion = 10; var requiredMinorVersion = 0; var requiredRevision = 45; ', CClientScript::POS_HEAD); Yii::app()->getClientScript()->registerScriptFile($chartUrl.'/AC_RunActiveContent.js',CClientScript::POS_BEGIN); ?>

<?php $chart = "<chart><chart_type>bar</chart_type><chart_border color='FF0000' /></chart>"; ?>

<script language="JavaScript" type="text/javascript"> /<![CDATA[/ if (AC_FL_RunContent == 0 || DetectFlashVer == 0) { alert("This page requires AC_RunActiveContent.js."); } else { var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); if(hasRightVersion) { AC_FL_RunContent( 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2', 'width', '400', 'height', '250', 'scale', 'noscale', 'salign', 'TL', 'bgcolor', '#777788', 'wmode', 'opaque', 'movie', 'charts', 'src', '<?php echo $chartUrl; ?>/charts', 'FlashVars', "library_path=<?php echo $chartUrl; ?>/charts_library&xml_data=<?php echo $chart; ?>", 'id', 'my_chart', 'name', 'my_chart', 'menu', 'true', 'allowFullScreen', 'true', 'allowScriptAccess','sameDomain', 'quality', 'high', 'align', 'middle', 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'play', 'true', 'devicefont', 'false' ); } else { var alternateContent = 'This content requires the Adobe Flash Player. ' + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.'; document.write(alternateContent); } } /]]>/

Note the relative path info on src and FlashVars is required.

最满意答案

据我所知, CClientScript保持通过registerScript()注册的脚本块和通过registerScript()注册的脚本的单独顺序。 但它总是在registerScript()之后呈现registerScriptFile() 。 有两种方法可以完成您的任务:

将脚本块放在CClientScript::POS_HEAD和CClientScript::POS_HEAD脚本链接中。 从CClientScript继承您自己的脚本管理器。

As far as I can tell, CClientScript keeps separate order of script blocks registered via registerScript() and scripts registered via registerScriptFile(). But it will always render registerScript() after registerScriptFile(). There are 2 possible ways to accomplish your task:

Place script blocks in CClientScript::POS_HEAD and script links in CClientScript::POS_END. Inherit your own script manager from CClientScript.

更多推荐

本文发布于:2023-07-22 00:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1215490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   JavaScript   Yii   XWF   Charts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!