当前位置: 首页>>代码示例>>PHP>>正文


PHP CJavaScript::jsonEncode方法代码示例

本文整理汇总了PHP中CJavaScript::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP CJavaScript::jsonEncode方法的具体用法?PHP CJavaScript::jsonEncode怎么用?PHP CJavaScript::jsonEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CJavaScript的用法示例。


在下文中一共展示了CJavaScript::jsonEncode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $tree = $this->getTree();
     # заплатка
     $tree = $tree[0]['children'];
     echo CJavaScript::jsonEncode($tree);
 }
开发者ID:BGCX261,项目名称:zoomtyre-svn-to-git,代码行数:7,代码来源:ajaxPartsAction.php

示例2: registerScript

 /**
  * Register Script
  */
 public function registerScript()
 {
     $basePath = Yii::getPathOfAlias('application.modules.user.views.asset');
     $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
     $cs = Yii::app()->getClientScript();
     $cs->registerCoreScript('jquery');
     $cs->registerCssFile($baseUrl . '/css/redmond/jquery-ui.css');
     $cs->registerCssFile($baseUrl . '/css/style.css');
     $cs->registerScriptFile($baseUrl . '/js/jquery-ui.min.js');
     $cs->registerScriptFile($baseUrl . '/js/form.js');
     $cs->registerScriptFile($baseUrl . '/js/jquery.json.js');
     $widgets = self::getWidgets();
     $wgByTypes = ProfileField::itemAlias('field_type');
     foreach ($wgByTypes as $k => $v) {
         $wgByTypes[$k] = array();
     }
     foreach ($widgets[1] as $widget) {
         if (isset($widget['fieldType']) && count($widget['fieldType'])) {
             foreach ($widget['fieldType'] as $type) {
                 array_push($wgByTypes[$type], $widget['name']);
             }
         }
     }
     //echo '<pre>'; print_r($widgets[1]); die();
     $js = "\n\n\tvar name = \$('#name'),\n\tvalue = \$('#value'),\n\tallFields = \$([]).add(name).add(value),\n\ttips = \$('.validateTips');\n\t\n\tvar listWidgets = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($widgets[0])) . "');\n\tvar widgets = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($widgets[1])) . "');\n\tvar wgByType = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($wgByTypes)) . "');\n\t\n\tvar fieldType = {\n\t\t\t'INTEGER':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':10,\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'VARCHAR':{\n\t\t\t\t'hide':['widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':255,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'TEXT':{\n\t\t\t\t'hide':['field_size','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DATE':{\n\t\t\t\t'hide':['field_size','field_size_min','match','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'0000-00-00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'FLOAT':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10.2',\n\t\t\t\t\t'default':'0.00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DECIMAL':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10,2',\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BOOL':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':0,\n\t\t\t\t\t'range':'1==" . UserModule::t('Yes') . ";0==" . UserModule::t('No') . "',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BLOB':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BINARY':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\t\n\tfunction showWidgetList(type) {\n\t\t\$('div.widget select').empty();\n\t\t\$('div.widget select').append('<option value=\"\">" . UserModule::t('No') . "</option>');\n\t\tif (wgByType[type]) {\n\t\t\tfor (var k in wgByType[type]) {\n\t\t\t\t\$('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tfunction setFields(type) {\n\t\tif (fieldType[type]) {\n\t\t\tif (" . (isset($_GET['id']) ? 0 : 1) . ") {\n\t\t\t\tshowWidgetList(type);\n\t\t\t\t\$('#widgetlist option:first').attr('selected', 'selected');\n\t\t\t}\n\t\t\t\n\t\t\t\$('div.row').addClass('toshow').removeClass('tohide');\n\t\t\tif (fieldType[type].hide.length) \$('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');\n\t\t\tif (\$('div.widget select').val()) {\n\t\t\t\t\$('div.widgetparams').removeClass('tohide');\n\t\t\t}\n\t\t\t\$('div.toshow').show(500);\n\t\t\t\$('div.tohide').hide(500);\n\t\t\t" . (!isset($_GET['id']) ? "\n\t\t\tfor (var k in fieldType[type].val) { \n\t\t\t\t\$('div.'+k+' input').val(fieldType[type].val[k]);\n\t\t\t}" : '') . "\n\t\t}\n\t}\n\t\n\tfunction isArray(obj) {\n\t\tif (obj.constructor.toString().indexOf('Array') == -1)\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\t\t\n\t\$('#dialog-form').dialog({\n\t\tautoOpen: false,\n\t\theight: 400,\n\t\twidth: 400,\n\t\tmodal: true,\n\t\tbuttons: {\n\t\t\t'" . UserModule::t('Save') . "': function() {\n\t\t\t\tvar wparam = {};\n\t\t\t\tvar fparam = {};\n\t\t\t\t\$('#dialog-form fieldset .wparam').each(function(){\n\t\t\t\t\tif (\$(this).val()) wparam[\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tvar tab = \$('#tabs ul li.ui-tabs-selected').text();\n\t\t\t\tfparam[tab] = {};\n\t\t\t\t\$('#dialog-form fieldset .tab-'+tab).each(function(){\n\t\t\t\t\tif (\$(this).val()) fparam[tab][\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tif (\$.JSON.encode(wparam)!='{}') \$('div.widgetparams input').val(\$.JSON.encode(wparam));\n\t\t\t\tif (\$.JSON.encode(fparam[tab])!='{}') \$('div.other_validator input').val(\$.JSON.encode(fparam)); \n\t\t\t\t\n\t\t\t\t\$(this).dialog('close');\n\t\t\t},\n\t\t\t'" . UserModule::t('Cancel') . "': function() {\n\t\t\t\t\$(this).dialog('close');\n\t\t\t}\n\t\t},\n\t\tclose: function() {\n\t\t}\n\t});\n\n\n\t\$('#widgetparams').focus(function() {\n\t\tvar widget = widgets[\$('#widgetlist').val()];\n\t\tvar html = '';\n\t\tvar wparam = (\$('div.widgetparams input').val())?\$.JSON.decode(\$('div.widgetparams input').val()):{};\n\t\tvar fparam = (\$('div.other_validator input').val())?\$.JSON.decode(\$('div.other_validator input').val()):{};\n\t\t\n\t\t// Class params\n\t\tfor (var k in widget.params) {\n\t\t\thtml += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\thtml += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />';\n\t\t}\n\t\t// Validator params\t\t\n\t\tif (widget.other_validator) {\n\t\t\tvar tabs = '';\n\t\t\tvar li = '';\n\t\t\tfor (var t in widget.other_validator) {\n\t\t\t\ttabs += '<div id=\"tab-'+t+'\" class=\"tab\">';\n\t\t\t\tli += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';\n\t\t\t\t\n\t\t\t\tfor (var k in widget.other_validator[t]) {\n\t\t\t\t\ttabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\t\t\tif (isArray(widget.other_validator[t][k])) {\n\t\t\t\t\t\ttabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';\n\t\t\t\t\t\tfor (var i in widget.other_validator[t][k]) {\n\t\t\t\t\t\t\ttabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>';\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttabs += '</select>';\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttabs += '</div>';\n\t\t\t}\n\t\t\thtml += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';\n\t\t}\n\t\t\n\t\t\$('#dialog-form fieldset').html(html);\n\t\t\n\t\t\$('#tabs').tabs();\n\t\t\n\t\t// Show form\n\t\t\$('#dialog-form').dialog('open');\n\t});\n\t\n\t\$('#field_type').change(function() {\n\t\tsetFields(\$(this).val());\n\t});\n\t\n\t\$('#widgetlist').change(function() {\n\t\tif (\$(this).val()) {\n\t\t\t\$('div.widgetparams').show(500);\n\t\t} else {\n\t\t\t\$('div.widgetparams').hide(500);\n\t\t}\n\t\t\n\t});\n\t\n\t// show all function \n\t\$('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">" . UserModule::t('Show all') . "</a>');\n \t\$('#showAll').click(function(){\n\t\t\$('div.row').show(500);\n\t\treturn false;\n\t});\n\t\n\t// init\n\tsetFields(\$('#field_type').val());\n\t\n\t";
     $cs->registerScript(__CLASS__ . '#dialog', $js);
 }
开发者ID:lidijakralj,项目名称:bober,代码行数:30,代码来源:ProfileFieldController.php

示例3: _returnJson

 protected function _returnJson($data)
 {
     $this->layout = false;
     header('Content-type: application/json');
     echo \CJavaScript::jsonEncode($data);
     \Yii::app()->end();
 }
开发者ID:radzserg,项目名称:yiirumor,代码行数:7,代码来源:Controller.php

示例4: actionAdditem

 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionAdditem($item_id)
 {
     $user_id = Yii::app()->user->id;
     // find the users cart
     $user = User::model()->find(array('condition' => 'id=:user_id', 'params' => array(':user_id' => $user_id)));
     // find the users cart
     $cart = Cart::model()->find(array('condition' => 'cart_owner=:cart_owner', 'params' => array(':cart_owner' => $user_id)));
     // find the item being reffered to by item_id
     $item = Item::model()->find(array('condition' => 'id=:item_id', 'params' => array(':item_id' => $item_id)));
     if (is_null($cart)) {
         // if the cart is not found. create a cart for the user.
         $cart = new Cart();
         $cart->cart_owner = $user->id;
         $cart->save();
     }
     // check if the same order was already made & increment else, create new
     $order = Order::model()->find(array('condition' => 'item_id=:item_id AND cart_id=:cart_id AND order_by=:order_by', 'params' => array(':item_id' => $item_id, ':cart_id' => $cart->id, ':order_by' => $user->id)));
     if (is_null($order)) {
         $order = new Order();
         $order->create_time = time();
         $order->quantity = 1;
         $order->item_id = $item->id;
         $order->cart_id = $cart->id;
         $order->order_by = $user->id;
     } else {
         $order->quantity = 1 + $order->quantity;
         $order->update_time = time();
     }
     $order->save();
     // find all orders by this user.
     $orders = Order::model()->findAll('cart_id=:cart_id AND order_by=:order_by', array(':cart_id' => $cart->id, ':order_by' => $user->id));
     $return = array('success' => true, 'data' => $orders);
     echo CJavaScript::jsonEncode($return);
     Yii::app()->end();
 }
开发者ID:iusedtobecat,项目名称:sweetparticles,代码行数:39,代码来源:CartController.php

示例5: run

 public function run()
 {
     Yii::import($this->import);
     $data = CHtml::listData(Brand::model()->findAll(array('order' => 'title')), 'id', 'title');
     $data[0] = '';
     ksort($data);
     echo CJavaScript::jsonEncode($data);
 }
开发者ID:BGCX261,项目名称:zoomtyre-svn-to-git,代码行数:8,代码来源:ajaxBrandsAction.php

示例6: actionGetJsonList

 public function actionGetJsonList()
 {
     // $professores = Professor::model()->findAll();
     // echo CJavaScript::jsonEncode($professores);
     $list = Yii::app()->db->createCommand('SELECT professor.id_professor, nome, aprovado, foto, AVG(voto) as nota FROM professor INNER JOIN voto ON voto.id_professor = professor.id_professor GROUP BY professor.id_professor')->queryAll();
     echo CJavaScript::jsonEncode($list);
     exit;
 }
开发者ID:andrewinston,项目名称:professoresdaect,代码行数:8,代码来源:ProfessorController.php

示例7: init

 public function init()
 {
     $options = CJavaScript::jsonEncode($this->options);
     $this->htmlOptions['onclick'] = strtr('WdatePicker({options});', array('{options}' => $options));
     $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'source';
     $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
     $cs = Yii::app()->getClientScript();
     $cs->registerScriptFile($this->baseUrl . '/WdatePicker.js');
 }
开发者ID:smoothcoder,项目名称:DISCARDEDYiiblog,代码行数:9,代码来源:JMy97DatePicker.php

示例8: actionUserList

 public function actionUserList()
 {
     $data = Jobs::model()->findAll(array('select' => 'uid', 'distinct' => true));
     $just_users = array();
     foreach ($data as $key => $value) {
         $just_users[] = $value["uid"];
     }
     echo CJavaScript::jsonEncode($just_users);
     Yii::app()->end();
 }
开发者ID:redsn0w422,项目名称:DarshanVis,代码行数:10,代码来源:JobsController.php

示例9: actionError

 /**
  * This is the action to handle external exceptions.
  */
 public function actionError()
 {
     if ($error = Yii::app()->errorHandler->error) {
         if (Yii::app()->request->isAjaxRequest) {
             header('Content-type: application/json');
             echo CJavaScript::jsonEncode(array('result' => 0, 'error' => $error));
         } else {
             $this->render('error', $error);
         }
     }
 }
开发者ID:sgaraba,项目名称:photo_gallery,代码行数:14,代码来源:SiteController.php

示例10: run

 public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         // this was set with the "max" attribute of the CAutoComplete widget
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->limit = $limit;
         $criteria->order = 'title';
         echo CJavaScript::jsonEncode(CHtml::listData(DiskProducers::model()->findAll($criteria), 'id', 'title'));
     }
 }
开发者ID:BGCX261,项目名称:zoomtyre-svn-to-git,代码行数:12,代码来源:DiskProducersListAction.php

示例11: registerClientScript

 /**
  * Registers required scripts
  */
 public function registerClientScript()
 {
     $id = $this->options['id'];
     $jsData = \CJavaScript::jsonEncode($this->data);
     $jsOptions = \CJavaScript::jsonEncode($this->options);
     $script = "\n\t\t\tgoogle.setOnLoadCallback(drawChart{$id});\n\t\t\tvar {$id}=null;\n\t\t\tfunction drawChart{$id}() {\n\t\t\t\tvar data = google.visualization.arrayToDataTable({$jsData});\n\n\t\t\t\tvar options = {$jsOptions};\n\n\t\t\t\t{$id} = new google.visualization.{$this->visualization}(document.getElementById('{$this->containerId}'));\n\t\t\t\t{$id}.draw(data, options);\n\t\t\t}";
     /** @var $cs \CClientScript */
     $cs = \Yii::app()->getClientScript();
     $cs->registerScriptFile('https://www.google.com/jsapi');
     $cs->registerScript(__CLASS__, 'google.load("visualization", "1", {packages:["corechart"]});', \CClientScript::POST_END);
     $cs->registerScript(md5($script), $script, \CClientScript::POS_END);
 }
开发者ID:abudayah,项目名称:yiiwheels-custom,代码行数:15,代码来源:Visualization.php

示例12: actionDetails

 public function actionDetails()
 {
     if (!isset($_REQUEST['name'])) {
         echo CJavaScript::jsonEncode(false);
     } else {
         $disorder = Disorder::model()->find('fully_specified_name = ? OR term = ?', array($_REQUEST['name'], $_REQUEST['name']));
         if ($disorder) {
             echo $disorder->id;
         } else {
             echo CJavaScript::jsonEncode(false);
         }
     }
 }
开发者ID:code-4-england,项目名称:OpenEyes,代码行数:13,代码来源:DisorderController.php

示例13: init

 public function init()
 {
     parent::init();
     if ($this->enable) {
         $cs = Yii::app()->clientScript;
         $params = array('BASEURL' => Yii::app()->request->baseUrl, 'HTTPHOST' => $_SERVER['HTTP_HOST']);
         $script = 'var PARAMS = eval(' . CJavaScript::jsonEncode($params) . ');';
         $cs->registerScript('widget-params', $script, CClientScript::POS_BEGIN);
         $cs->registerScriptFile(Yii::app()->request->baseUrl . '/js/persist.js', CClientScript::POS_HEAD);
         $script = implode('', file(Yii::app()->basePath . '/../js/widget-collapse.min.js'));
         $cs->registerScript('widget-collapse', $script, CClientScript::POS_READY);
     }
 }
开发者ID:purnachandra,项目名称:yii-blogdemo-extended,代码行数:13,代码来源:WidgetCollapse.php

示例14: actionDeleteComment

 public function actionDeleteComment()
 {
     $return['status'] = 0;
     $id = Yii::app()->request->getPost('id');
     $model = $this->loadModel($id);
     if (!$model || $model->owner_id != Yii::app()->user->id && !Yii::app()->user->checkAccess('backend_access')) {
         $return['message'] = tt('commentNotFound', 'comments');
     } else {
         $model->delete();
         $return['status'] = 1;
     }
     echo CJavaScript::jsonEncode($return);
 }
开发者ID:barricade86,项目名称:raui,代码行数:13,代码来源:MainController.php

示例15: run

 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $data = CHtml::listData(Modification::model()->findAll(array('condition' => 'model_id=' . $id, 'order' => 'title')), 'id', 'title');
         $data[0] = '';
         ksort($data);
         echo CJavaScript::jsonEncode($data);
     }
 }
开发者ID:BGCX261,项目名称:zoomtyre-svn-to-git,代码行数:13,代码来源:ajaxModificationsAction.php


注:本文中的CJavaScript::jsonEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。