/**
  * Before render callback.
  *
  * @param \Cake\Event\Event $event The beforeRender event.
  * @return void
  */
 public function beforeRender(Event $event)
 {
     if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) {
         $this->set('_serialize', true);
     }
     Time::setToStringFormat('dd/MM/yy, HH:MM');
     Time::setJsonEncodeFormat('dd/MM/yy, HH:MM');
     $this->set('renderLayoutTitle', $this->renderLayoutTitle);
     $this->set('userLoggedIn', $this->Auth->user());
 }
Example #2
0
 /**
  * Tests encoding a Time object as json
  *
  * @return void
  */
 public function testJsonEnconde()
 {
     $time = new Time('2014-04-20 10:10:10');
     $this->assertEquals('"2014-04-20T10:10:10+0000"', json_encode($time));
     Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
     $this->assertEquals('"2014-04-20 10:10:10"', json_encode($time));
 }
 public function getPostsWithTag()
 {
     Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
     date_default_timezone_set('America/Sao_Paulo');
     if ($this->request->is('post')) {
         $result = $this->Posts->find('byTagName', ['tag' => $this->request->data['data']]);
         $this->paginate = ['maxLimit' => 10, 'order' => ['Posts.post_date' => 'desc']];
         if ($result == null) {
             echo 'algo deu errado =/';
         } else {
             $this->set('posts', $this->paginate($result));
             $this->render('pagination-container');
         }
     } else {
         echo 'its not post request';
     }
 }
Example #4
0
<?php

/**
 * Encoding     :   UTF-8
 * Created on   :   2015-12-26 22:58:51 by allen <blog.rc5j.cn> , caowenpeng1990@126.com
 */
require dirname(__FILE__) . '/function.php';
//引入全局函数文件
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\Database\Type\TimeType;
use Cake\I18n\Time;
spl_autoload_register(function ($class) {
    //  echo $class;
    //include_once  dirname(__FILE__) . '/' . str_replace('\\', '/', $class) . 'php';
});
//TimeType::$dateTimeClass = 'Admin\I18n\DateOnly';
Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
if (PHP_SAPI === 'cli') {
    // Attach bake events here.
    EventManager::instance()->on('Bake.beforeRender.Controller.controller', function (Event $event) {
        $view = $event->subject();
        //        if(strpos('Admin.', $view->viewVars['plugin'])!==FALSE){
        if ($view->theme == 'Admin') {
            // add the login and logout actions to the Users controller
            $view->viewVars['actions'] = ['index', 'view', 'add', 'edit', 'delete', 'getDataList', 'exportExcel'];
        }
        //        if ($view->viewVars['name'] == 'Admin') {
    });
}