Fancybox2 - php in javascript?

Hello all

I’m trying to create myself an extension for the new Fancybox2, and i’ve run into a big problem.

I want to to load fancybox gallery with a link.

Looks like:


<a class="open_fancybox"><div class="fancybox-button"></div></a>

I’ve build my “extension” up from an old fancybox extension:http://www.yiiframework.com/extension/fancybox/

and the run() function looks something like this:


$config = CJavaScript::encode($this->config);

$images = CJavaScript::encode($this->images);

		

Yii::app()->clientScript->registerScript('fancyBox', "

$('.open_fancybox').click(function() {

  $.fancybox.open(

    $images,  

    $config

  );

  return false;  

});

Then i load the extension in the view, with the following:


$this->widget('application.extensions.fancybox2.EFancyBox2', 

  array(

    'images'=>array(

      array('href'=>'http://fancyapps.com/fancybox/demo/1_b.jpg',),

      array('href'=>'http://fancyapps.com/fancybox/demo/2_b.jpg',),

    ), 

    'config'=>array(

      'helpers'=>array(

        'title'=>array('type'=>'over'),

	'thumbs'=>array(

	  'width'=>100,

	  'height'=>100,

	  'position'=>'bottom',

	),

      ),

      'mouseWheel'=>true,

      'arrows'=>true,

      'nextClick'=>true,

      'loop'=>true,

      'openEffect'=>'none',

      'closeEffect'=>'none',

      'prevEffect'=>'fade',

      'nextEffect'=>'fade',

      'padding'=>0,		

    ),

  )

);

This is all working just fine - weeehuu…

BUT… I want the gallery to be dynamicly.

So i need a way to insert the arrays:


array('href'=>'http://fancyapps.com/fancybox/demo/1_b.jpg',),

from my database…

How do i insert data into javascript from php, and “echo” it as actual javascript…???

try this




$images = Model::model()->findAll();


$fancyBoxImages = array();


foreach($images as $image) {

  $fancyBoxImages[] = array('href'=> $image->path );

}


// then you have array of images you can pass that array to images


'images'=> $fancyBoxImages, 

I think i love you alirz23 !!! :D

Actually i already tried something similar, but with a bit different output…

I foreached this:

$gallery = “array(‘href’=>’”.$images."’,),";

and of course that doesnt work!

But again thank you very much!! :)