本文整理汇总了PHP中Pw::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Pw::jsonEncode方法的具体用法?PHP Pw::jsonEncode怎么用?PHP Pw::jsonEncode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pw
的用法示例。
在下文中一共展示了Pw::jsonEncode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterAction
public function afterAction($handlerAdapter)
{
parent::afterAction($handlerAdapter);
$debug = Wekit::C('site', 'debug') || !Wekit::C('site', 'css.compress');
Wekit::setGlobal(array('debug' => $debug ? '/dev' : '/build'), 'theme');
$this->setTheme('site', null);
/* @var $resource WindLangResource */
$resource = Wind::getComponent('i18n');
$_error = $this->getForward()->getVars('message');
if ($resource !== null) {
foreach ($_error as $key => $value) {
if (is_array($value)) {
list($value, $var) = $value;
} else {
$var = array();
}
$message = $resource->getMessage($value, $var);
$message && ($_error[$key] = $message);
}
}
$this->getForward()->setVars(array('message' => $_error, '__error' => ''));
$type = $this->getRequest()->getAcceptTypes();
// 如果是含有上传的递交,不能采用ajax的方式递交,需要以html的方式递交,并且返回的结果需要是json格式,将以json=1传递过来标志
$json = $this->getInput('_json');
$requestJson = $this->getRequest()->getIsAjaxRequest() && strpos(strtolower($type), "application/json") !== false;
if ($requestJson || $json == 1) {
$this->getResponse()->setHeader('Content-type', 'application/json; charset=' . Wekit::V('charset'));
echo Pw::jsonEncode($this->getForward()->getVars());
exit;
}
}
示例2: forumlistAction
public function forumlistAction()
{
$forums = Wekit::load('forum.PwForum')->getForumList(PwForum::FETCH_ALL);
$service = Wekit::load('forum.srv.PwForumService');
$map = $service->getForumMap();
$cate = array();
$forum = array();
foreach ($map[0] as $key => $value) {
if (!$value['isshow']) {
continue;
}
$array = $service->findOptionInMap($value['fid'], $map, array('sub' => '--', 'sub2' => '----'));
$tmp = array();
foreach ($array as $k => $v) {
$forumset = $forums[$k]['settings_basic'] ? unserialize($forums[$k]['settings_basic']) : array();
$isAllowPoll = isset($forumset['allowtype']) && is_array($forumset['allowtype']) && in_array('poll', $forumset['allowtype']);
if ($forums[$k]['isshow'] && $isAllowPoll && (!$forums[$k]['allow_post'] || $this->loginUser->inGroup(explode(',', $forums[$k]['allow_post'])))) {
$tmp[$k] = strip_tags($v);
}
}
if ($tmp) {
$cate[$value['fid']] = $value['name'];
$forum[$value['fid']] = $tmp;
}
}
$response = array('cate' => $cate, 'forum' => $forum);
$this->setOutput(Pw::jsonEncode($response), 'data');
$this->showMessage('success');
}
示例3: run
public function run()
{
header("Content-type: text/html; charset=" . Wekit::app()->charset);
//$pwServer['HTTP_USER_AGENT'] = 'Shockwave Flash';
$swfhash = 1;
echo Pw::jsonEncode(array('uid' => $this->loginUser->uid, 'a' => 'dorun', 'verify' => $swfhash));
$this->setTemplate('');
}
示例4: schoolAction
/**
* 学校获取(typeid = 1:小学,2:中学,3:大学)
*/
public function schoolAction()
{
list($type, $areaid, $name, $first) = $this->getInput(array('typeid', 'areaid', 'name', 'first'));
!$type && ($type = 3);
Wind::import('WINDID:service.school.vo.WindidSchoolSo');
$schoolSo = new WindidSchoolSo();
$schoolSo->setName($name)->setTypeid($type)->setFirstChar($first)->setAreaid($areaid);
$list = WindidApi::api('school')->searchSchoolData($schoolSo, 1000);
exit($list ? Pw::jsonEncode($list) : '');
}
示例5: afterAction
/**
* 重写下afterAction,不去i18n解析
*
*/
public function afterAction($handlerAdapter)
{
$_error = $this->getForward()->getVars('message');
$this->getForward()->setVars(array('message' => $_error, '__error' => ''));
$type = $this->getRequest()->getAcceptTypes();
if ($this->getRequest()->getIsAjaxRequest() && strpos(strtolower($type), "application/json") !== false) {
$this->getResponse()->setHeader('Content-type', 'application/json; charset=' . Wekit::V('charset'));
exit(Pw::jsonEncode($this->getForward()->getVars()));
}
}
示例6: output
protected function output($message = '')
{
if (is_numeric($message)) {
echo $message;
exit;
} else {
header('Content-type: application/json; charset=' . Wekit::V('charset'));
echo Pw::jsonEncode($message);
exit;
}
}
示例7: schoolAction
/**
* 学校获取(typeid = 1:小学,2:中学,3:大学)
*/
public function schoolAction()
{
list($type, $areaid, $name, $first) = $this->getInput(array('typeid', 'areaid', 'name', 'first'));
!$type && ($type = 3);
Wind::import('SRV:school.srv.vo.PwWindidSchoolSo');
$schoolSo = new PwWindidSchoolSo();
$schoolSo->setName($name)->setTypeid($type)->setFirstChar($first)->setAreaid($areaid);
/* @var $schoolService PwSchoolService */
$schoolService = Wekit::load('school.srv.PwSchoolService');
$list = $schoolService->searchSchool($schoolSo, 1000);
exit($list ? Pw::jsonEncode($list) : '');
}
示例8: myDraftsAction
/**
* 发帖页我的草稿
*
* @return void
*/
public function myDraftsAction()
{
$drafts = $this->_getDraftDs()->getByUid($this->loginUser->uid, $this->maxNum);
$data = array();
foreach ($drafts as $v) {
$_tmp['id'] = $v['id'];
$_tmp['title'] = $v['title'];
$_tmp['content'] = $v['content'];
$_tmp['created_time'] = Pw::time2str($v['created_time'], 'auto');
$data[] = $_tmp;
}
echo Pw::jsonEncode(array('state' => 'success', 'data' => $data));
exit;
}
示例9: jsonFormat
protected function jsonFormat($moduleId)
{
$_data = array();
Wind::import('SRV:design.bo.PwDesignModuleBo');
$bo = new PwDesignModuleBo($moduleId);
$module = $bo->getModule();
if ($module['module_type'] != PwDesignModule::TYPE_SCRIPT) {
exit('fail');
}
$data = $bo->getData(true);
header('Content-type: application/json');
echo Pw::jsonEncode($data);
exit;
}
示例10: getfollowAction
/**
* 获取用户关注数据,ajax输出
*
*/
public function getfollowAction()
{
list($type, $page, $perpage) = $this->getInput(array('type', 'page', 'perpage'));
$page = $page ? $page : 1;
$perpage = $perpage ? $perpage : $this->perpage;
list($start, $limit) = Pw::page2limit($page, $perpage);
$typeCounts = $this->_getAttentionTypeDs()->countUserType($this->loginUser->uid);
if ($type) {
$tmp = $this->_getAttentionTypeDs()->getUserByType($this->loginUser->uid, $type, $limit, $start);
$follows = $this->_getAttentionDs()->fetchFollows($this->loginUser->uid, array_keys($tmp));
$count = $typeCounts[$type] ? $typeCounts[$type]['count'] : 0;
} else {
$follows = $this->_getAttentionDs()->getFollows($this->loginUser->uid, $limit, $start);
$count = $this->loginUser->info['follows'];
}
$uids = array_keys($follows);
echo Pw::jsonEncode(array('state' => 'success', 'data' => $this->_buildRemindUsers($uids), 'page' => $page));
exit;
}
示例11: showErrorMessage
protected function showErrorMessage($message, $file, $line, $trace, $errorcode)
{
list($fileLines, $trace) = $this->crash($file, $line, $trace);
if (Wind::$isDebug & 2) {
$log = $message . "\r\n" . $file . ":" . $line . "\r\n";
foreach ($trace as $key => $value) {
$log .= $value . "\r\n";
}
Wind::getComponent('windLogger')->error($log, 'error', true);
}
$message = nl2br($message);
//render json
$type = $this->getRequest()->getAcceptTypes();
// 如果是含有上传的递交,不能采用ajax的方式递交,需要以html的方式递交,并且返回的结果需要是json格式,将以json=1传递过来标志
$json = $this->getRequest()->getRequest('_json');
$requestJson = $this->getRequest()->getIsAjaxRequest() && strpos(strtolower($type), "application/json") !== false;
if ($requestJson || $json == 1) {
Wind::$isDebug & 1 && ($message = nl2br($message . "\r\n" . $file . ":" . $line . "\r\n"));
$this->getResponse()->setHeader('Content-type', 'application/json; charset=' . $this->getResponse()->getCharset());
echo Pw::jsonEncode(array('referer' => null, 'refresh' => null, 'state' => 'fail', 'message' => $message));
exit;
}
$errDir = Wind::getRealPath($this->errorDir, false);
if ($this->isClosed) {
$errPage = 'close';
} elseif (is_file($errDir . '/' . $errorcode . '.htm')) {
$errPage = $errorcode;
} else {
$errPage = 'error';
}
$title = $this->getResponse()->codeMap($errorcode);
$title = $title ? $errorcode . ' ' . $title : 'unknowen error';
$__vars['title'] = ucwords($title);
$__vars['message'] = $message;
if (Wind::$isDebug & 1) {
$__vars['debug']['file'] = $file;
$__vars['debug']['line'] = $line;
$__vars['debug']['trace'] = $trace;
$__vars['debug']['fileLines'] = $fileLines;
}
$this->render($__vars, $errorcode, $errDir, $errPage);
}
示例12: doSendAction
/**
* do群发消息
*
* @return void
*/
public function doSendAction()
{
list($type, $content, $title, $step, $countStep) = $this->getInput(array('type', 'content', 'title', 'step', 'countStep'));
!$content && $this->showError('Message:content.empty');
if ($step > $countStep) {
$this->showMessage("ADMIN:success");
}
$step = $step ? $step : 1;
switch ($type) {
case 1:
// 根据用户组
list($user_groups, $grouptype) = $this->getInput(array('user_groups', 'grouptype'));
Wind::import('SRV:user.vo.PwUserSo');
$vo = new PwUserSo();
$searchDs = Wekit::load('SRV:user.PwUserSearch');
if (!$user_groups) {
$this->showError('Message:user.groups.empty');
}
if ($grouptype == 'memberid') {
$vo->setMemberid($user_groups);
} else {
$vo->setGid($user_groups);
}
$count = $searchDs->countSearchUser($vo);
$countStep = ceil($count / $this->perstep);
if ($step <= $countStep) {
list($start, $limit) = Pw::page2limit($step, $this->perstep);
$userInfos = $searchDs->searchUser($vo, $limit, $start);
}
break;
case 2:
// 根据用户名
$touser = $this->getInput('touser');
!$touser && $this->showError('Message:receive.user.empty');
$touser = explode(' ', $touser);
$count = count($touser);
$countStep = ceil($count / $this->perstep);
if ($step <= $countStep) {
$userDs = Wekit::load('user.PwUser');
list($start, $limit) = Pw::page2limit($step, $this->perstep);
$userInfos = $userDs->fetchUserByName(array_slice($touser, $start, $limit));
}
break;
case 3:
// 根据在线用户(精确在线)
$onlineService = Wekit::load('online.srv.PwOnlineCountService');
list($count, $userInfos) = $onlineService->getVisitorList('', $step, $this->perstep, true);
$countStep = ceil($count / $this->perstep);
break;
}
$result = $this->sendNoticeByUsers((array) $userInfos, $content, strip_tags($title));
if ($result instanceof PwError) {
$this->showError($result->getError());
}
$haveBuild = $step * $this->perstep;
$haveBuild = $haveBuild > $count ? $count : $haveBuild;
$step++;
usleep(500);
$data = array('step' => $step, 'countStep' => $countStep, 'count' => $count, 'haveBuild' => $haveBuild);
echo Pw::jsonEncode(array('data' => $data));
exit;
}
示例13: _initTopictypes
private function _initTopictypes($defaultTopicType = 0)
{
$topictypes = $jsonArray = array();
$forceTopicType = $this->post->forum->forumset['force_topic_type'];
if ($this->post->forum->forumset['topic_type']) {
$permission = $this->loginUser->getPermission('operate_thread', false, array());
$topictypes = $this->_getTopictypeDs()->getTopicTypesByFid($this->post->forum->fid, !$permission['type']);
foreach ($topictypes['sub_topic_types'] as $key => $value) {
if (!is_array($value)) {
continue;
}
// if (!$forceTopicType && $value) $jsonArray[$key][$key] = '无分类';
foreach ($value as $k => $v) {
$jsonArray[$key][$k] = strip_tags($v['name']);
}
}
}
if ($defaultTopicType && isset($topictypes['all_types'][$defaultTopicType])) {
$defaultParentTopicType = $topictypes['all_types'][$defaultTopicType]['parentid'];
} else {
$defaultTopicType = $defaultParentTopicType = 0;
}
$json = Pw::jsonEncode($jsonArray);
$this->setOutput($defaultTopicType, 'defaultTopicType');
$this->setOutput($defaultParentTopicType, 'defaultParentTopicType');
$this->setOutput($topictypes, 'topictypes');
$this->setOutput($json, 'subTopicTypesJson');
$this->setOutput($forceTopicType ? 1 : 0, 'forceTopic');
$this->setOutput('1', 'isTopic');
}
示例14: followsAction
/**
* 获取我关注的人
*
* @return void
*/
public function followsAction()
{
list($page, $perpage, $type) = $this->getInput(array('page', 'perpage', 'type'));
$page = $page ? $page : 1;
$perpage = $perpage ? $perpage : $this->perpage;
list($start, $limit) = Pw::page2limit($page, $perpage);
$attentionDs = Wekit::load('attention.PwAttention');
$type = $type ? $type : 'follows';
if ($type == 'follows') {
$count = $this->loginUser->info['follows'];
$count && ($attentions = $attentionDs->getFollows($this->loginUser->uid, $limit, $start));
} else {
$count = $this->loginUser->info['fans'];
$count && ($attentions = $attentionDs->getFans($this->loginUser->uid, $limit, $start));
}
if (!$attentions) {
echo Pw::jsonEncode(array('state' => 'fail'));
exit;
}
$uids = array_keys($attentions);
$attentions = Wekit::load('user.PwUser')->fetchUserByUid($uids);
echo Pw::jsonEncode(array('state' => 'success', 'data' => $attentions));
exit;
}
示例15: punchtipAction
/**
* 请求获取tip
*
*/
public function punchtipAction()
{
$punchData = $this->loginUser->info['punch'];
$punchData = $punchData ? unserialize($punchData) : array();
$reward = $this->config['punch.reward'];
if (!$punchData) {
$data = array('cUnit' => $this->_creditBo->cUnit[$reward['type']], 'cType' => $this->_creditBo->cType[$reward['type']], 'todaycNum' => $reward['min'], 'tomorrowcNum' => $reward['min'] + $reward['step'], 'step' => $reward['step'], 'max' => $reward['max']);
echo Pw::jsonEncode(array('state' => 'success', 'data' => $data));
exit;
}
$havePunch = $this->_getPunchService()->isPunch($punchData);
if ($punchData['username'] == $this->loginUser->username && $havePunch) {
echo Pw::jsonEncode(array('state' => 'fail'));
exit;
}
$behavior = $this->_getUserBehaviorDs()->getBehavior($this->loginUser->uid, 'punch_day');
$steps = $behavior['number'] > 0 ? $behavior['number'] : 0;
$awardNum = $reward['min'] + $steps * $reward['step'] > $reward['max'] ? $reward['max'] : $reward['min'] + $steps * $reward['step'];
$tomorrowcNum = $awardNum + $reward['step'];
$data = array('cUnit' => $this->_creditBo->cUnit[$reward['type']], 'cType' => $this->_creditBo->cType[$reward['type']], 'todaycNum' => $awardNum, 'tomorrowcNum' => $tomorrowcNum > $reward['max'] ? $reward['max'] : $tomorrowcNum, 'step' => $reward['step'], 'max' => $reward['max']);
echo Pw::jsonEncode(array('state' => 'success', 'data' => $data));
exit;
}