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. 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>
Sign up to request clarification or add additional context in comments.

4 Comments

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
I am agree and I have tried both method but none of them is working. Could you please help.
@Neeraj or eskimo, Could you guys help me with the images
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.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.