本文整理汇总了PHP中CJSON::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP CJSON::decode方法的具体用法?PHP CJSON::decode怎么用?PHP CJSON::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CJSON
的用法示例。
在下文中一共展示了CJSON::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: decodeJson
/**
* Decodes JSON sting.
*
* @static
*
* @param string $data
* @param bool $asArray get result as array instead of object
*
* @return mixed
*/
public static function decodeJson($data, $asArray = true)
{
if (self::$json === null) {
self::$json = new CJSON();
}
return self::$json->decode($data, $asArray);
}
示例3: actions
public function actions()
{
$formSettings = array('redirect' => $this->createUrl('admin'), 'forms' => array('id' => 'mainForm', 'varName' => 'cmsAlias', 'models' => 'CmsAlias', 'onAfterSave' => function ($event) {
$model = $event->params['model'];
if ($model->location != 'nochange') {
$decode = CJSON::decode($_POST['CmsAlias']['location']);
$to = CmsAlias::model()->findByPk((int) $decode['to']);
$action = $decode['action'];
switch ($action) {
case 'child':
$model->moveAsLast($to);
break;
case 'before':
if ($to->isRoot()) {
$model->moveAsRoot();
} else {
$model->moveBefore($to);
}
break;
case 'after':
if ($to->isRoot()) {
$model->moveAsRoot();
} else {
$model->moveAfter($to);
}
break;
}
}
}, 'forms' => array('id' => 'routesForm', 'models' => 'CmsAliasRoute', 'varName' => 'cmsAliasRoutes', 'parentIdAttribute' => 'alias_id')));
return array('create' => array('class' => 'application.components.actions.Create', 'formSettings' => $formSettings), 'update' => array('class' => 'application.components.actions.Update', 'formSettings' => $formSettings), 'delete' => array('class' => 'application.components.actions.Delete', 'modelClass' => 'CmsAlias'), 'admin' => array('class' => 'application.components.actions.Admin', 'modelClass' => 'CmsAlias'));
}
示例4: runAction
public function runAction($action, $data)
{
$this->id = $data;
$s = new CHttpSession();
$s->open();
$storedData = $s[$this->id];
$s->close();
$this->model = $storedData['model'];
if ($action == 'listitems') {
$parent_id = null;
if (isset($_GET['id'])) {
$parent_id = $_GET['id'];
}
return $this->model->eyuiformeditordb_listitems($_GET['item_type'], $parent_id);
}
if ($action == 'newitem') {
$parent_id = null;
if (isset($_GET['id'])) {
$parent_id = $_GET['id'];
}
return $this->model->eyuiformeditordb_newitem($_GET['item_type'], self::t("New Item"), $parent_id);
}
if ($action == 'deleteitem') {
if ($this->model->eyuiformeditordb_deleteitem($_GET['id'])) {
return "OK";
}
}
if ($action == 'updateitem') {
$obj = CJSON::decode(trim(file_get_contents('php://input')));
if ($this->model->eyuiformeditordb_updateitem($obj) == true) {
return "OK";
}
}
}
示例5: actionEditCustomer
public function actionEditCustomer($id)
{
$data = CJSON::decode(file_get_contents('php://input'));
$customer = Customer::model()->findByPk($id);
if (!$customer) {
$response = array('success' => false, 'message' => 'Couldn\'t find customer with id = ' . $id);
$this->renderJSON($response);
}
$orders = array();
if (isset($data['orders'])) {
$orders = $data['orders'];
unset($data['orders']);
}
$customer->attributes = $data;
$customer->save();
if (count($orders)) {
$ordersArray = array();
foreach ($orders as $order) {
$order = array('customer_id' => $id, 'posted_at' => $order['postedAt'], 'amount' => $order['amount'], 'paid_at' => $order['paidAt']);
$orderModel = new Order();
$orderModel->attributes = $order;
$orderModel->save();
}
}
$response = array('success' => true);
$this->renderJSON($response);
}
示例6: getAvailableUpdate
/**
* Returns all available updates for a given version
*
* @param type $version
*/
public static function getAvailableUpdate()
{
try {
$url = Yii::app()->getModule('updater')->getApiUrl() . "getHumHubUpdates?version=" . urlencode(HVersion::VERSION) . "&updaterVersion=" . Yii::app()->getModule('updater')->getVersion();
$http = new Zend_Http_Client($url, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => Yii::app()->getModule('updater')->getCurlOptions(), 'timeout' => 30));
$response = $http->request();
$body = $response->getBody();
if ($body == "") {
return null;
}
$info = CJSON::decode($body);
if (!isset($info['fromVersion'])) {
return null;
}
$package = new UpdatePackage();
$package->versionFrom = $info['fromVersion'];
$package->versionTo = $info['toVersion'];
$package->fileName = $info['fileName'];
$package->md5 = $info['md5'];
$package->downloadUrl = $info['downloadUrl'];
return $package;
} catch (Exception $ex) {
throw new CHttpException('500', Yii::t('UpdaterModule.base', 'Could not get update info online! (%error%)', array('%error%' => $ex->getMessage())));
}
return null;
}
示例7: authenticate
public function authenticate()
{
$user = User::model()->findByAttributes(array('username' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
// check Auto or Not
$password = $this->autoLogin == false ? MSecure::password($this->username . $this->password . $user->registered) : $this->password;
if ($user->password !== $password) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
if ($user->lastvisited === NULL) {
$lastLogin = new CDbExpression('NOW()');
} else {
$lastLogin = $user->lastvisited;
}
// RBAC
$roles = CJSON::decode($user->role);
$auth = Yii::app()->authManager;
foreach ($roles as $role) {
if (!$auth->isAssigned($role, $this->_id)) {
if ($auth->assign($role, $this->_id)) {
Yii::app()->authManager->save();
}
}
}
$this->setState('email', $user->email);
$this->setState('lastvisited', $lastLogin);
$this->errorCode = self::ERROR_NONE;
}
}
return !$this->errorCode;
}
示例8: actionIndex
public function actionIndex()
{
$shop_id = Yii::app()->request->getParam('shop_id');
if (!$shop_id) {
Error::output(Error::ERR_NO_SHOPID);
}
//查询出改商店的一些详细信息
$shopData = Shops::model()->findByPk($shop_id);
if (!$shopData) {
Error::output(Error::ERR_NO_SHOPID);
}
$shopData = CJSON::decode(CJSON::encode($shopData));
//根据店铺id查询出该店铺的菜单
$menuData = Menus::model()->with('food_sort', 'image', 'shops')->findAll(array('condition' => 't.shop_id=:shop_id AND t.status=:status', 'params' => array(':shop_id' => $shop_id, ':status' => 2)));
$data = array();
foreach ($menuData as $k => $v) {
$data[$k] = $v->attributes;
$data[$k]['index_pic'] = $v->index_pic ? Yii::app()->params['img_url'] . $v->image->filepath . $v->image->filename : '';
$data[$k]['sort_name'] = $v->food_sort->name;
$data[$k]['shop_name'] = $v->shops->name;
$data[$k]['create_time'] = Yii::app()->format->formatDate($v->create_time);
$data[$k]['status'] = Yii::app()->params['menu_status'][$v->status];
$data[$k]['price'] = $v->price;
}
Out::jsonOutput(array('shop' => $shopData, 'menus' => $data));
}
示例9: beforeSave
public function beforeSave()
{
$ip = Yii::app()->request->userHostAddress;
$key = 'ipInfo-' . $ip;
$ipData = zmf::getCookie($key);
if (!$ipData) {
$url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=' . $ip;
// 执行HTTP请求
$header = array('apikey:e5882e7ac4b03c5d6f332b6de4469e81');
$ch = curl_init();
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
$res = CJSON::decode($res, true);
$retData = array();
if ($res['errNum'] == 0) {
$retData = $res['retData'];
}
$ipData = json_encode($retData);
zmf::setCookie($key, $ipData, 2592000);
}
$this->ip = ip2long($ip);
$this->ipInfo = $ipData;
return true;
}
示例10: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
//read the post input (use this technique if you have no post variable name):
$post = file_get_contents("php://input");
//decode json post input as php array:
$data = CJSON::decode($post, true);
//Event is a Yii model:
$evento = new Evento();
//load json data into model:
$evento->attributes = $data;
//this is for responding to the client:
$response = array();
//save model, if that fails, get its validation errors:
if ($evento->save() == false) {
$response['success'] = false;
$response['errors'] = $evento->errors;
} else {
$response['success'] = true;
//respond with the saved contact in case the model/db changed any values
//$response['evento'] = $evento;
}
//respond with json content type:
header('Content-type:application/json');
//encode the response as json:
echo CJSON::encode($response);
exit;
}
示例11: actionAddnewaduan
public function actionAddnewaduan()
{
//read the post input (use this technique if you have no post variable name):
$post = file_get_contents("php://input");
//decode json post input as php array:
$data = CJSON::decode($post, true);
echo $data;
//read the post input (use this technique if you have no post variable name):
// $post = file_get_contents("php://input");
//decode json post input as php array:
// $data = CJSON::decode($post, true);
// $showjson = json_decode($post);
// $result = file_get_contents('php://input');
// echo $result;
// $post = Yii::$app->request->post();
// $get = json_decode($result);
// // Get data from object
// $member = $get->member;
// $judul = $get->judul;
// $deskripsi = $get->deskripsi;
// $category = $get->category;
// $kecamatan = $get->kecamatan;
// echo '<h1>Ngantuk</h1>';
// Your code.....
// $model = new ModelAduan();
// // if ($model->load(Yii::$app->request->post())) {
// $data = $model->AddNewUser($member, $judul, $deskripsi, $category, $kecamatan);
// sukses
// echo json_encode(array('data' => $result, 'status' => '1'));
// }else{
// // gagal
// echo json_encode(array('status' => '2'));
// }
// URL : http://back.end/index.php?r=api/addnewaduan
}
示例12: logout
/**
* @test
* @depends reLoginAndCheckToken
* @param string $token
*/
public function logout($token)
{
$route = 'logout/';
$this->handlePost(401, null, $route);
$response = \CJSON::decode($this->handlePost(200, array('access_token' => $token), $route)->getBody()->getContents());
$this->assertTrue(time() >= $response['expire']);
}
示例13: complete
private function complete()
{
$required = array('social_service' => true);
$params = $this->controller->getParams($required);
/**
* @var Quest[] $socialQuests
*/
$socialQuests = Quest::model()->byUser($this->controller->identity->getId())->byType(QuestTypes::POST_TO_WALL)->byModel((new \ReflectionClass(ContestManager::getCurrentActive()))->getShortName(), ContestManager::getCurrentActive()->id)->findAll();
if (!in_array($params['social_service'], array('vk', 'ok', 'fb'))) {
throw new InvalidParamsApiException();
}
/**
* @var CommentatorsContestParticipant $participant
*/
$participant = CommentatorsContestParticipant::model()->byContest(ContestManager::getCurrentActive()->id)->byUser($this->controller->identity->getId())->find();
foreach ($socialQuests as $quest) {
if (\CJSON::decode($quest->settings)['social_service'] == $params['social_service']) {
$quest->complete();
$this->controller->data = $quest;
$participant->score += 25;
$participant->update(array('score'));
break;
}
}
if (!$this->controller->data) {
throw new NotFoundApiException();
}
}
示例14: run
public function run()
{
$params = array();
$criteria = new CDbCriteria();
$criteria->select = array('lecture_name,training_minute,id,lecture_type');
if (isset($this->lecture_name) and $this->lecture_name != '') {
$keyword = addcslashes($this->lecture_name, '%_');
$criteria->addCondition('lecture_name LIKE :keyword');
$params[':keyword'] = "%{$keyword}%";
}
if (isset($this->lecture_cat) and $this->lecture_cat != '') {
$criteria->addCondition('lecture_cat_id=' . $this->lecture_cat);
}
if (isset($this->trainer) and $this->trainer != '') {
$criteria->addCondition('created_by=' . $this->trainer);
}
if (!empty(Yii::app()->user->id) and Yii::app()->session['group_id'] == 1) {
$criteria->addCondition('created_by=' . Yii::app()->user->id);
}
$criteria->params = $params;
$criteria->order = 'created_date DESC';
$total = Lecture::model()->count($criteria);
$offset = $this->limit * ($this->page - 1);
$criteria->limit = $this->limit;
$criteria->offset = $offset;
$data = Lecture::model()->findAll($criteria);
if (!empty($data)) {
$data = CJSON::decode(CJSON::encode($data));
}
$pages = new CPagination($total);
$pages->pageSize = $this->limit;
$pages->applyLimit($criteria);
$this->render($this->view, array('data' => $data, 'pages' => $pages));
}
示例15: actionSaveAnswer
public function actionSaveAnswer()
{
$request = CJSON::decode(file_get_contents('php://input'));
if ($request) {
echo CJSON::encode(Answers::saveAnswer($request));
}
}