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:

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() {





  return false;  


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




























This is all working just fine - weeehuu…

BUT… I want the gallery to be dynamicly.

So i need a way to insert the arrays:


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!! :)