0

I am trying to implement Supersized slider with my Yii project. In order to implement I have to implement some javascript in the view. So I decided to go with the registerscript method. But I think I am not able to initialized the directory location of the images. Could you help me

My code is

<?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
  • I am getting undefind directory error.
    – Ashish
    Commented Jan 16, 2013 at 6:10

1 Answer 1

2

Try This Way..

<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>
4
  • You should not be using absolute paths (localhost) , you should use Yii base URL Yii::app()->request->baseUrl which points to the root (you could also use getcwd()). The reason is that when you upload it your live server you will have to find and replace all these paths. Using base URL makes the application more portable Commented Jan 16, 2013 at 8:18
  • I am agree and I have tried both method but none of them is working. Could you please help.
    – Ashish
    Commented Jan 16, 2013 at 14:44
  • @Neeraj or eskimo, Could you guys help me with the images
    – Ashish
    Commented Jan 16, 2013 at 19:05
  • first check the link to the images, run your code from the browser and use "Inspect Element" to check the images, if the images are loaded, then there is certainly some problem in the jquery code..... Commented Jan 20, 2013 at 9:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.