register javascript code

Inside my view I write some javascript code that inside has php code also

<script type="text/javascript">

    var mytext='<?php echo yii::t('main','Select files.')?>'

    var imgbases='<?php echo Yii::app()->request->baseUrl?>'

    function funcOpen (branch, response) {

        // Ici tu peux traiter le retour et retourner true si

        // tu veux insιrer les enfants, false si tu veux pas

        return true;


How can I use the $cs->registerScript with that code?

Yii::app()->clientScript->registerScript('mytext', "var mytext='" . Yii::t('main','Select files.') . "';");

Yii::app()->clientScript->registerScript('imgbases', "var imgbases='" . Yii::app()->request->baseUrl . "';")

You can also add the funcOpen function, but since it’s static anyway I would just put it into a js file.

I have also another function that has php code that take parameters from the controller

...function TafelTreeInit () {

        var struct = [

<?php $i=10;

foreach ($files as $key => $value) {?>{

            'id':'<?php echo $value['relative_path']."/".$key;?>',

            'txt':'<?php  echo date("d-m-Y H:i:s.",$value['date'])?>',

            'canhavechildren' : true


    <?php    }  ?>...

I thing there is way to put to a variable something with in a few lines but I do not remember.