Hi,

Kai Meder wrote:
$this->roles is array from db-select
json() is kindof shortcut to Zend_Json::encode

<?php $this->jsVar('ROLES', json($this->roles)); ?>

which results in:
<script type="text/javascript">var ROLES = "{\"Writer\":{\"role\":\"Writer\"}}";</script>

full helper-source:
<?php
class Zend_View_Helper_JsVar {

    public function jsVar($name, $value) {
echo '<script type="text/javascript">';
        echo 'var ' . $name . ' = ';
        echo json($value);
        echo ';';
        echo '</script>';
        echo "\n";
    }
}

the whole thing is quoted twice and it seems to be the view's fault.

in the call to $this->jsVar you pass a JSON encoded value, which is a string. In the helper function you encode the $value a second time, hence the escaped string.
Removing one off the json() call's will fix it.

Kind regards
Stefan

Reply via email to