本文整理汇总了PHP中CJSON::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP CJSON::encode方法的具体用法?PHP CJSON::encode怎么用?PHP CJSON::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CJSON
的用法示例。
在下文中一共展示了CJSON::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$id = Yii::app()->request->getParam('id');
$type = Yii::app()->request->getParam('type');
$userId = Yii::app()->request->getParam('userId');
$hub = Yii::app()->request->getParam('hub');
$startTime = Yii::app()->request->getParam('startTime');
$endTime = Yii::app()->request->getParam('endTime');
$room = Yii::app()->request->getParam('room');
$data = array('type' => $type, 'userId' => $userId, 'hubId' => $hub, 'startTime' => $startTime, 'endTime' => $endTime, 'conferenceroomId' => $room);
$proxy = new BReservation();
$dc = new BConference();
$dp = new BHub();
if (Yii::app()->request->isAjaxRequest) {
$result = $proxy->updateReservation($data, $id);
echo CJSON::encode($result);
} else {
$result = $proxy->getReservationInfo($id);
$hub = $dp->getHubList($start, 10);
$room = $dc->getRoomList($start, 10);
if ($result['code'] == 200) {
$this->controller->render('edit', array('data' => $result['data'], 'hub' => $hub['data'], 'room' => $room['data']));
} else {
throw new CHttpException($result['code'], $result['message']);
}
}
}
示例2: run
public function run()
{
$params = array();
$criteria = new CDbCriteria();
// $criteria->select = array('id,username,fullname,phone,address,status');
$criteria->select = '*';
if (isset($this->team_lear_id) and $this->team_lear_id != '') {
$criteria->addCondition('team_lear_id=' . $this->team_lear_id);
}
$criteria->params = $params;
$total = ATrainingTeam::model()->count($criteria);
$offset = $this->limit * ($this->page - 1);
$criteria->limit = $this->limit;
$criteria->offset = $offset;
$data = ATrainingTeam::model()->findAll($criteria);
$listTrainee = array();
if (!empty($data)) {
foreach ($data as $item) {
$listTrainee[] = CJSON::decode(CJSON::encode($item->pls_user));
}
}
$data = $listTrainee;
$pages = new CPagination($total);
$pages->pageSize = $this->limit;
$pages->applyLimit($criteria);
$this->render($this->view, array('data' => $data, 'pages' => $pages));
}
示例3: encodeJson
/**
* Encodes the data as a JSON string to be used in JavaScript code.
*
* @static
*
* @param mixed $data
* @param bool $forceObject force all arrays to objects
*
* @return mixed
*/
public static function encodeJson($data, $forceObject = false)
{
if (self::$json === null) {
self::$json = new CJSON();
}
return self::$json->encode($data, array(), $forceObject);
}
示例4: send
/**
* Output ajax response. If any error was added, 'result' is false, otherwise true.
*
* @return void
*/
public function send()
{
$json = new CJSON();
if ($this->_result) {
echo $json->encode(array('result' => true, 'data' => $this->_data));
} else {
echo $json->encode(array('result' => false, 'errors' => $this->_errors));
}
}
示例5: run
/**
* Display editor
*/
public function run()
{
// Resolve name and id
list($name, $id) = $this->resolveNameID();
// Get assets dir
$baseDir = dirname(__FILE__);
$assets = Yii::app()->getAssetManager()->publish($baseDir . DIRECTORY_SEPARATOR . 'ueditor1_2_5');
// Publish required assets
$cs = Yii::app()->getClientScript();
$jsFile = $this->debug ? 'editor_all.js' : 'editor_all_min.js';
$cs->registerScriptFile($assets . '/' . $jsFile);
$cs->registerScriptFile($assets . '/editor_config.js');
$this->htmlOptions['id'] = $id;
if (!array_key_exists('style', $this->htmlOptions)) {
$this->htmlOptions['style'] = "width:{$this->width};";
}
if ($this->toolbars) {
$this->editorOptions['toolbars'][] = $this->toolbars;
}
$options = CJSON::encode(array_merge(array('theme' => $this->theme, 'lang' => $this->language, 'UEDITOR_HOME_URL' => "{$assets}/", 'initialFrameWidth' => $this->width, 'initialFrameHeight' => $this->height), $this->editorOptions));
$js = <<<EOP
UE.getEditor('{$id}',{$options});
EOP;
// Register js code
$cs->registerScript('Yii.' . get_class($this) . '#' . $id, $js, CClientScript::POS_READY);
// Do we have a model
if ($this->hasModel()) {
$html = CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
} else {
$html = CHtml::textArea($name, $this->value, $this->htmlOptions);
}
echo $html;
}
示例6: actionSend
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionSend()
{
$model = new Reports();
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if (isset($_POST['Reports'])) {
$model->attributes = $_POST['Reports'];
$jsonError = CActiveForm::validate($model);
if (strlen($jsonError) > 2) {
echo $jsonError;
} else {
if (isset($_GET['enablesave']) && $_GET['enablesave'] == 1) {
if ($model->save()) {
echo CJSON::encode(array('type' => 5, 'get' => Yii::app()->controller->createUrl('send', array('type' => 'success'))));
} else {
print_r($model->getErrors());
}
}
}
Yii::app()->end();
} else {
$this->dialogDetail = true;
$this->dialogGroundUrl = Yii::app()->createUrl('site/index');
$this->dialogWidth = 500;
$this->pageTitle = Phrase::trans(12014, 1);
$this->pageDescription = '';
$this->pageMeta = '';
$this->render('front_send', array('model' => $model));
}
}
示例7: makeBuilderPredefinedEmailTemplate
protected function makeBuilderPredefinedEmailTemplate($name, $unserializedData, $subject = null, $modelClassName = null, $language = null, $type = null, $isDraft = 0, $textContent = null, $htmlContent = null)
{
$emailTemplate = new EmailTemplate();
$emailTemplate->type = $type;
//EmailTemplate::TYPE_WORKFLOW;
$emailTemplate->builtType = EmailTemplate::BUILT_TYPE_BUILDER_TEMPLATE;
$emailTemplate->isDraft = $isDraft;
$emailTemplate->modelClassName = $modelClassName;
$emailTemplate->name = $name;
if (empty($subject)) {
$subject = $name;
}
$emailTemplate->subject = $subject;
if (!isset($language)) {
$language = Yii::app()->languageHelper->getForCurrentUser();
}
$emailTemplate->language = $language;
$emailTemplate->htmlContent = $htmlContent;
$emailTemplate->textContent = $textContent;
$emailTemplate->serializedData = CJSON::encode($unserializedData);
$emailTemplate->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$saved = $emailTemplate->save(false);
if (!$saved) {
throw new FailedToSaveModelException();
}
$emailTemplate = EmailTemplate::getById($emailTemplate->id);
ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($emailTemplate, Group::getByName(Group::EVERYONE_GROUP_NAME));
$saved = $emailTemplate->save(false);
assert('$saved');
}
示例8: run
/**
* Suggests models based on the current user input.
*/
public function run()
{
if (isset($_GET['term']) && ($keyword = trim($_GET['term'])) !== '') {
$suggest = $this->getModel()->{$this->methodName}($keyword, $this->limit, $_GET);
echo CJSON::encode($suggest);
}
}
示例9: actionIndex
/**
* Returns a List of all notifications for an user
*/
public function actionIndex()
{
// the id from the last entry loaded
$lastEntryId = (int) Yii::app()->request->getParam('from');
// create database query
$criteria = new CDbCriteria();
if ($lastEntryId > 0) {
// start from last entry id loaded
$criteria->condition = 'id<:lastEntryId';
$criteria->params = array(':lastEntryId' => $lastEntryId);
}
$criteria->order = 'seen ASC, created_at DESC';
$criteria->limit = 6;
// safe query
$notifications = Notification::model()->findAllByAttributes(array('user_id' => Yii::app()->user->id), $criteria);
// variable for notification list
$output = "";
foreach ($notifications as $notification) {
// format and save all entries
$output .= $notification->getOut();
// get the id from the last entry
$lastEntryId = $notification->id;
}
// build json array
$json = array();
$json['output'] = $output;
$json['lastEntryId'] = $lastEntryId;
$json['counter'] = count($notifications);
// return json
echo CJSON::encode($json);
// compete action
Yii::app()->end();
}
示例10: init
public function init()
{
//Yii::app()->setTheme('adm');
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/global.js');
$cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery-ui.min.js');
$cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.alerts.js');
//$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/js/jquery.confirm.js');
//$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/js/jquery.blockui.js');
$cs->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery-ui-1.8.2.custom.min.js');
//$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/js/bsystemgroup.js');
$cs->registerCssFile(Yii::app()->theme->baseUrl . '/css/jquery.alerts.css');
Yii::app()->clientScript->registerScript('global', '
yii = {
urls: {
base: ' . CJSON::encode(Yii::app()->theme->baseUrl) . '
}
};
', CClientScript::POS_HEAD);
if (Yii::app()->user->id) {
$user = new ASystemUser();
$userInfo = $user->getSystemUserById(Yii::app()->user->id);
//var_dump($userInfo->cp_code);exit();
$this->group_id = $userInfo->group_id;
$this->username = $userInfo->username;
Yii::app()->session['group_id'] = $this->group_id;
Yii::app()->session['username'] = $this->username;
}
//$xmlPath = realpath($path = Yii::app()->basePath.'/../'.Yii::app()->params['config_folder'].'/');
// $xmlFile = Yii::app()->params['config_file_name'];
// $this->config = new LoadConfigXML($xmlPath,$xmlFile);
Yii::$classMap = array_merge(Yii::$classMap, array('CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedAction.php', 'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended') . DIRECTORY_SEPARATOR . 'CaptchaExtendedValidator.php'));
}
示例11: run
public function run()
{
$galleryItemType = $this->albumItemType;
$item_id = Yii::app()->request->getParam('gitem_id');
$model = $galleryItemType::model()->findByPk($item_id);
if (!$model) {
throw new CHttpException(404);
}
$target_id = $model->target_id;
if (!Yii::app()->user->checkAccess('album_deleteGItem', array('item' => $model))) {
throw new CHttpException(403);
}
$afterDeleteHandler = function ($event) {
$originalPath = $event->sender->path;
$filesPathes = Yii::app()->getModule('album')->getAbsolutePathes($originalPath);
foreach ($filesPathes as $path) {
if (file_exists($path)) {
unlink($path);
}
}
};
$model->attachEventHandler('onAfterDelete', $afterDeleteHandler);
if (!$model->delete()) {
throw new CException('Item #' . $item_id . ' deletion failed');
}
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('success' => true, 'html' => Yii::t('album.messages', 'Элемент был удален успешно')));
Yii::app()->end();
}
$this->redirect(array($this->getModule()->rootRoute, 'target_id' => $target_id));
}
示例12: actionIndex
public function actionIndex()
{
// Return all Diseases
$response = array();
$response['PhotoPath'] = Yii::app()->params['siteDomain'] . Yii::app()->params['imagePath'];
$response['Entries'] = array();
$response['Photos'] = array();
$response['PhotoLinker'] = array();
$tubers = Tuber::model()->findAll();
if ($tubers != null) {
// Have something to return..
// Get images for each entry.
foreach ($tubers as $tuber) {
// Get all images for current tuber entry.
$images = $tuber->images;
if ($images != null) {
foreach ($images as $image) {
$response['PhotoLinker'][] = array('Id' => $image->Id, 'EntryId' => $image->TuberId, 'PhotoId' => $image->PhotoId);
$response['Photos'][] = array("Id" => $image->photo->Id, "ImageName" => $image->photo->Name, "EntryId" => $tuber->Id);
}
}
$response['Entries'][] = $tuber;
}
}
$this->sendResponse(200, CJSON::encode($response));
}
示例13: actionUpdate
public function actionUpdate($id)
{
if (null === ($model = User::model()->findByPk($id))) {
throw new CHttpException(404);
}
$data = CJSON::decode(file_get_contents('php://input'));
$model->fname = $data['fname'];
$model->lname = $data['lname'];
$model->email = $data['email'];
$model->username = $data['username'];
$model->role = $data['role'];
$model->newPassword = $data['password'];
if ($model->newPassword) {
$model->password = $model->newPassword;
}
if (!$model->save()) {
$errors = array();
foreach ($model->getErrors() as $e) {
$errors = array_merge($errors, $e);
}
$this->sendResponse(500, implode("<br />", $errors));
}
$model = User::model()->noPassword()->findByPk($model->id);
$this->sendResponse(200, CJSON::encode($model));
}
示例14: actionSave_comment
/**
* Добавление / редактирование комментариев
*/
public function actionSave_comment()
{
if (Yii::app()->user->isGuest) {
$this->redirect($this->createAbsoluteUrl('base'));
}
// Редактирование или добавление новой
if (isset($_GET['idComment'])) {
$model = Comments::model()->findByPk($_GET['idComment']);
} else {
$model = new Comments();
}
if (isset($_POST['idArticle']) && isset($_POST['text']) && isset($_POST['idAuthor'])) {
$model->idArticle = $_POST['idArticle'];
$model->text = $_POST['text'];
$model->idUser = empty($this->_user) ? Users::getIdUserForAdmin() : $this->_user['idUser'];
$model->typeUser = $model->idUser == $_POST['idAuthor'] ? 'author' : (empty($this->_user) ? 'admin' : 'user');
if ($model->save()) {
if (Yii::app()->request->isAjaxRequest) {
$criteria = new CDbCriteria();
$criteria->with = array('idUser0');
$criteria->condition = 'idArticle = :idArticle AND deleted = 0 AND public = 1';
$criteria->params = array(':idArticle' => $_POST['idArticle']);
$comments = Comments::model()->findAll($criteria);
$commentsDataProvider = new CArrayDataProvider($comments, array('keyField' => 'idComment', 'pagination' => array('pageSize' => 50)));
$listComments = $this->renderPartial('_list_comments', array('dataProvider' => $commentsDataProvider), true);
echo CJSON::encode(array('listComments' => $listComments));
exit;
}
}
}
}
示例15: actionAnyFileData
public function actionAnyFileData($id = null, $model = 'Partner', $filename = 'image', $realname = false)
{
$result = array();
$id = (int) $id;
$model = $model::model()->findByPk($id);
if (!$model) {
echo '[]';
Yii::app()->end();
throw new CHttpException(404, Yii::t('site', 'Page not found'));
}
$uploadPath = $model->getFileFolder();
if ($model->{$filename}) {
$obj['id'] = $model->id;
//get the filename in array
if ($realname) {
$obj['name'] = $model->{$realname};
} else {
$obj['name'] = $model->{$filename};
}
if (file_exists($uploadPath . $model->{$filename})) {
$obj['size'] = filesize($uploadPath . $model->{$filename});
//get the flesize in array
} else {
$obj['size'] = '0';
}
$result[] = $obj;
// copy it to another array
}
header('Content-Type: application/json');
echo CJSON::encode($result);
Yii::app()->end();
}