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


PHP Zend_Json_Encoder类代码示例

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


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

示例1: encode

 /**
  * Use the JSON encoding scheme for the value specified
  *
  * @param mixed $value  value the object to be encoded
  * @return string  The encoded value
  */
 public static function encode($value)
 {
     if (empty($value)) {
         return 'null';
     }
     $encoder = new Zend_Json_Encoder();
     return $encoder->_encodeValue($value);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:14,代码来源:Encoder.php

示例2: setFromArray

 /**
  * Metoda logująca zmiany wprowadzane w poszczególnych tabelach.
  * W celu skorzystania należy w pliku Row modelu ustawić
  * pole $_logEnable na true
  * @param type $array
  * @throws Zend_Db_Table_Row_Exception
  */
 public function setFromArray(array $array)
 {
     $row = parent::setFromArray($array);
     if ($this->getLogEnable()) {
         try {
             $logger = Zend_Registry::get('log_app');
         } catch (Exception $e) {
             throw new Zend_Db_Table_Row_Exception('The logger "log_app" for row changes log is not set!', 0, $e);
         }
         $changeData = $this->getAllModified();
         if ($changeData['old'] != null && $changeData['new'] != null) {
             $old = Zend_Json_Encoder::encode($changeData['old']);
             $new = Zend_Json_Encoder::encode($changeData['new']);
             $id = $this->_getPrimaryKey();
             $logger->setEventItem('table_name', $this->getTable()->getName());
             $logger->setEventItem('schema_name', $this->getTable()->info('schema'));
             $logger->setEventItem('new', $new);
             if ($id[$this->getIterator()->key()] != null) {
                 $logger->setEventItem('row_id', $id[$this->getIterator()->key()]);
                 $logger->setEventItem('old', $old);
                 $logger->info('update');
             } else {
                 $logger->setEventItem('row_id', $this->save());
                 $logger->info('insert');
             }
         }
     }
     return $row;
 }
开发者ID:knatorski,项目名称:SMS,代码行数:36,代码来源:Row.php

示例3: errorAction

 /**
  * Default error action.
  *
  * On Phprojekt_PublishedException, return an error string in JSON format.
  * <pre>
  *  - type    => 'error'.
  *  - message => Error message.
  *  - code    => Error code.
  * </pre>
  *
  * On wrong controller name or action, terminates script execution.
  *
  * In all cases, the error is logged.
  *
  * @return void
  */
 public function errorAction()
 {
     $error = $this->_getParam('error_handler');
     $this->getResponse()->clearBody();
     switch ($error->type) {
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             // 404 error -- controller or action not found
             $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
             $message = "The url " . Cleaner::sanitize('xss', urldecode($error->request->getRequestUri())) . " do not exists";
             Phprojekt::getInstance()->getLog()->err($message);
             die($message);
             break;
         default:
             $exception = $error->exception;
             // We only forward exception with type PublishedException
             if ($exception instanceof Phprojekt_PublishedException) {
                 $error = array('type' => 'error', 'message' => $exception->getMessage(), 'code' => $exception->getCode());
                 echo '{}&&(' . Zend_Json_Encoder::encode($error) . ')';
             } else {
                 $logger = Phprojekt::getInstance()->getLog();
                 $logger->err($exception->getMessage() . "\n" . $exception->getTraceAsString());
             }
             break;
     }
 }
开发者ID:penSecIT,项目名称:PHProjekt,代码行数:42,代码来源:ErrorController.php

示例4: postJsonContext

 /**
  * JSON post processing
  *
  * JSON serialize view variables to response body
  *
  * @return void
  */
 public function postJsonContext()
 {
     if (!$this->_actionController->getHelper('contextSwitch')->getAutoJsonSerialization()) {
         return;
     }
     $viewRenderer = \Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $view = $viewRenderer->view;
     if ($view instanceof \Zend_View_Interface) {
         /**
          * @see \Zend_Json
          */
         if (method_exists($view, 'getVars')) {
             $response = null;
             $exceptionMessage = null;
             if ($this->getResponse()->isException()) {
                 $exceptionMessage = $view->message . ' : ' . $view->exception->getMessage();
             } else {
                 $response = $view->getVars();
             }
             $body = array('error' => $exceptionMessage, 'result' => $response);
             $this->getResponse()->setBody(\Zend_Json_Encoder::encode($body));
         } else {
             require_once 'Zend/Controller/Action/Exception.php';
             throw new \Zend_Controller_Action_Exception('View does not implement the getVars() method needed to encode the view into JSON');
         }
     }
 }
开发者ID:lukaszjankowski,项目名称:alchemy,代码行数:34,代码来源:JsonContext.php

示例5: putAction

 /**
  * Function putAction for for putting the file from client to server.
  */
 public function putAction()
 {
     $asResponse = array('status' => 'Ok', 'massage' => 'successfull execution of put method');
     $ssResponse = Zend_Json_Encoder::encode($asResponse);
     echo $ssResponse;
     exit;
 }
开发者ID:nainit-virtueinfo,项目名称:zend-rest,代码行数:10,代码来源:RestserverController.php

示例6: execute

 function execute($task)
 {
     if (!isset($task)) {
         $this->display();
     }
     if ($task) {
         switch ($task) {
             case "wsCity":
                 $regionId = JRequest::getVar('regionId', '0', 'GET', 'string');
                 $countryId = JRequest::getVar('countryId', '0', 'GET', 'string');
                 $productName = JRequest::getVar('productName', '0', 'GET', 'string');
                 $objectXML = $this->getXMLCities($regionId, $countryId, $productName);
                 $retval = $this->callService($objectXML);
                 $valueReturn = array();
                 if (isset($retval["city"]["item"])) {
                     if (!isset($retval["city"]["item"][0])) {
                         $valueReturn["item"][0] = $retval["city"]["item"];
                     } else {
                         $valueReturn["item"] = $retval["city"]["item"];
                     }
                 }
                 die(Zend_Json_Encoder::encode($valueReturn));
                 break;
             case "wsCountryName":
                 $geographic = JRequest::getVar('Geographic', '', 'GET', 'string');
                 $resultsGetGeographic = $this->getCountryName($geographic);
                 die($resultsGetGeographic);
                 break;
         }
     }
 }
开发者ID:jmangarret,项目名称:webtuagencia24,代码行数:31,代码来源:controller.php

示例7: servicoAction

 public function servicoAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $servicos = $this->getServicos();
     echo Zend_Json_Encoder::encode($servicos);
 }
开发者ID:nandorodpires2,项目名称:guiamais,代码行数:7,代码来源:BuscaController.php

示例8: json_region

 /**
  * 
  */
 public function json_region()
 {
     header('Content-type: application/json');
     $id = $this->input->post('id');
     $region = $this->_region_model->getById($id);
     echo Zend_Json_Encoder::encode(array("id" => $region->reg_ia_id, "nombre" => $region->reg_c_nombre, "lat" => $region->lat, "lon" => $region->lon));
 }
开发者ID:CarlosAyala,项目名称:midas-codeigniter-modulo-emergencias,代码行数:10,代码来源:region.php

示例9: addeditAction

 /**
  * Function addeditAction for add and edit the user's information.
  */
 public function addeditAction()
 {
     $oForm = new Application_Form_AddUsers();
     $oForm->submit->setLabel('Save');
     if ($this->getRequest()->getParam('id') != '' && is_numeric($this->getRequest()->getParam('id'))) {
         unset($oForm->password);
     }
     if ($this->getRequest()->isPost()) {
         if ($oForm->isValid($this->getRequest()->getPost())) {
             $asUserDetail = $oForm->getValues();
             $ssUserDetail = Zend_Json_Encoder::encode($asUserDetail);
             $client = new Zend_Http_Client($this->ssUri . '/addedit');
             $client->setConfig(array('timeout' => 30));
             $client->setParameterPost(array('ssUserDetail' => $ssUserDetail, 'bIsRest' => true));
             $ssResponse = $client->request('POST');
             if ($ssResponse->isSuccessful()) {
                 $ssResponseBody = $ssResponse->getBody();
                 $asResponse = Zend_Json_Decoder::decode($ssResponseBody, Zend_Json::TYPE_ARRAY);
                 if ($asResponse['status'] == 'success') {
                     $this->_redirect('/restclient/list');
                 }
             }
         }
     } elseif ($this->getRequest()->getParam('id') != '') {
         $oUser = Model_UsersTable::findUser($this->getRequest()->getParam('id'));
         $oForm->populate($oUser[0]);
     }
     $this->view->snIdUser = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '';
     $this->view->form = $oForm;
 }
开发者ID:nainit-virtueinfo,项目名称:zend-rest,代码行数:33,代码来源:RestclientController.php

示例10: preDispatch

 /**
  * Query the ACL if the user is allowed to be dispatched to the resource
  *
  * @param Zend_Controller_Request_Abstract $request
  * @throws Zend_Exception if user is not allowed (handled by error controller)
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $resource = $module . '/' . $controller;
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity() === TRUE) {
         $user = $auth->getIdentity();
     } else {
         $user = new App_User();
         $user->setRole(Zend_Registry::get('acl_default_role_name'), Zend_Registry::get('acl_default_role_id'));
     }
     $auth->getStorage()->write($user);
     /**
      * load acl stuff from cache.
      * the acl is created, that it doesnot grab the data from the database again
      * so, we should have a little bit of performance here
      */
     /*
             //FIXME: ACL Caching seems be faulty or its the development process
             //       After changing rules, ACL doesn't match anymore
             //       Fix: After Changing roles/rules refresh the ACL Cache Object
             $cache = Zend_Registry::get('Cache_Acl');
             $acl   = $cache->load('acl_object');
             IF(!$acl) {
        $acl = new App_Acl;
             }
     */
     $acl = new App_Acl();
     // FIXME: remove after above is fixed
     $acl->buildResourceRules($module, $controller, $action, $user);
     // $cache->save($acl, 'acl_object'); // FIXME: enabled again after above problem is fixed
     foreach ($user->getRoles() as $roleId => $roleName) {
         if ($acl->isAllowed($roleId, $resource, $action)) {
             return TRUE;
         }
         foreach ($acl->getRole($roleId)->getParentRole() as $roleId => $roleName) {
             if ($acl->isAllowed($roleId, $resource, $action)) {
                 return TRUE;
             }
         }
     }
     /**
      * This part is critical (see todo in class docs)
      *
      * 1. On XML Requests:
      *      The setbody just adds information to the body. If an php error occure, the
      *      setBody just prepend the this error to the php error => the return is an Json/html mixed response, unreadable for Ajax Client
      * 2. normal HTTP resposen:
      *      anonymouse rerouting to login page, no reason or any notification to the user
      */
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setBody(Zend_Json_Encoder::encode(array('success' => FALSE, 'error_message' => 'No Right to execute this action')));
     } elseif ($controller !== 'error') {
         $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
         $redirector->gotoSimple('login', 'auth', 'noc');
     }
 }
开发者ID:kevindragon221,项目名称:Webdesktop,代码行数:65,代码来源:Acl.php

示例11: testProcessInputData

 public function testProcessInputData()
 {
     $response = new Zend_Http_Response(200, array(), Zend_Json_Encoder::encode($this->testArgs));
     $args = $this->proc->processInputData($response);
     $this->assertEquals($args, $this->testArgs, 'Received JSON data should be decoded');
     $args = $this->proc->processInputData();
     $this->assertEquals($args, array(), 'When a response is not provided we should return an empty array');
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:8,代码来源:JsonInputProcessorTest.php

示例12: _setReturn

 /**
  * @param string $string
  * @param bool   $jsonEncode
  *
  * @return $this
  */
 protected function _setReturn($string = '', $jsonEncode = FALSE)
 {
     if (TRUE === $jsonEncode) {
         $this->getResponse()->setHeader('Content-type', 'application/json', TRUE);
     }
     $this->getResponse()->setBody($jsonEncode ? Zend_Json_Encoder::encode($string) : $string);
     return $this;
 }
开发者ID:ho-nl-fork,项目名称:magento1-SchumacherFM_Markdown,代码行数:14,代码来源:MarkdownController.php

示例13: encode

 /**
  * Encode the mixed $valueToEncode into the JSON format
  *
  * Encodes using ext/json's json_encode() if available.
  *
  * NOTE: Object should not contain cycles; the JSON format
  * does not allow object reference.
  *
  * NOTE: Only public variables will be encoded
  *
  * @param mixed $valueToEncode
  * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
  * @return string JSON encoded object
  */
 public static function encode($valueToEncode, $cycleCheck = false)
 {
     if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
         return json_encode($valueToEncode);
     }
     require_once 'vtwsclib/third-party/Zend/Json/Encoder.php';
     return Zend_Json_Encoder::encode($valueToEncode, $cycleCheck);
 }
开发者ID:mbcraft,项目名称:frozen,代码行数:22,代码来源:Zend_Json.class.php

示例14: encode

 /**
  * Encode the mixed $valueToEncode into the JSON format
  *
  * Encodes using ext/json's json_encode() if available.
  *
  * NOTE: Object should not contain cycles; the JSON format
  * does not allow object reference.
  *
  * NOTE: Only public variables will be encoded
  *
  * @param mixed $valueToEncode
  * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
  * @return string JSON encoded object
  */
 public static function encode($valueToEncode, $cycleCheck = false)
 {
     if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
         return json_encode($valueToEncode);
     }
     import('lib.Json.Encoder');
     return Zend_Json_Encoder::encode($valueToEncode, $cycleCheck);
 }
开发者ID:Rudi9719,项目名称:lucid,代码行数:22,代码来源:Json.php

示例15: encode

 /**
  * Encode the mixed $valueToEncode into the JSON format
  *
  * Encodes using ext/json's json_encode() if available.
  *
  * NOTE: Object should not contain cycles; the JSON format
  * does not allow object reference.
  *
  * NOTE: Only public variables will be encoded
  *
  * @param mixed $valueToEncode
  * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
  * @return string JSON encoded object
  */
 public static function encode($valueToEncode, $cycleCheck = false)
 {
     if (function_exists('json_encode')) {
         return json_encode($valueToEncode);
     }
     include_once 'Zend/Json/Encoder.php';
     return Zend_Json_Encoder::encode($valueToEncode, $cycleCheck);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:22,代码来源:Json.php


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