无法包含javascript

时间:2013-01-16 05:49:32

标签: javascript jquery yii

我正在尝试使用我的Yii项目实现Supersized滑块。为了实现我必须在视图中实现一些javascript。所以我决定使用registercript方法。但我想我无法初始化图像的目录位置。你能帮我吗

我的代码是

<?php   

$script= <<<EOD
jQuery(function($){             
    $.supersized({
        slide_interval          :7000,  // Length between transitions
    transition              :1,     // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
    transition_speed    :1000,  // Speed of transition
    slide_links     :'blank',// Individual links for each slide (Options: false, 'num', 'name', 'blank')
    slides          :[// Slideshow Images
                $directory = Yii::getPathOfAlias('webroot').'/uploads/';
                $images = glob($directory . "*.{jpg,JPG,jpeg,JPEG,png,PNG}", GLOB_BRACE);
                foreach($images as $image)
                echo "{image : 'http://localhost/uploads/" . $image . "', title : '" .$image . "'},";
                ]   
            });
            });
EOD;
Yii::app()->clientScript->registerScript('customFnc', $script, CClientScript::POS_READY);?>

1 个答案:

答案 0 :(得分:2)

试试这个......

<script>
            jQuery(function($){             
                $.supersized({
                  slide_interval          :7000,  // Length between transitions
                  transition              :1,     // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
                  transition_speed    :1000,  // Speed of transition
                  slide_links     :'blank',// Individual links for each slide (Options: false, 'num', 'name', 'blank')
                  slides          :[// Slideshow Images
     <?php
                            $directory = Yii::getPathOfAlias('webroot').'/uploads/';
                            $images = glob($directory . "*.{jpg,JPG,jpeg,JPEG,png,PNG}", GLOB_BRACE);
                            foreach($images as $image)
                            echo "{image : 'http://localhost/uploads/" . $image . "', title : '" .$image . "'},"; ?>

                            ]   
                        });
                        });
            </script>