/**
  * @param array $log[table_name, action, created_by, primary_key, description]
  * @return void, if cannot write to logs table, log file will be used
  * @throws \Cake\Database\Exception
  */
 function log_activity(array $log)
 {
     if (empty($log)) {
         return;
     }
     $Logs = Cake\ORM\TableRegistry::get('Logs');
     $logObj = $Logs->newEntity();
     $logObj->table_name = $log['table_name'];
     $logObj->action = $log['action'];
     $logObj->created_by = $log['created_by'];
     $logObj->recycle = false;
     $logObj->primary_key = $log['primary_key'];
     $logObj->description = $log['description'];
     if (!$Logs->save($logObj)) {
         \Cake\Log\Log::alert(__('Cannot write user login activity to logs: {0}', implode(',', $log)));
     }
 }
use Cake\Datasource\ConnectionManager;
// DIC configuration
$container = $app->getContainer();
$container['errorHandler'] = function ($c) {
    return function ($request, $response, $exception) use($c) {
        $code = 500;
        $errorCode = $exception->getCode();
        if ($errorCode >= 400 && $errorCode < 506) {
            $code = $errorCode;
        }
        return $c['response']->withStatus($code);
    };
};
// view renderer
$container['renderer'] = function ($c) {
    $settings = $c->get('settings')['renderer'];
    return new Slim\Views\PhpRenderer($settings['template_path']);
};
// monolog
$container['logger'] = function ($c) {
    $settings = $c->get('settings')['logger'];
    $logger = new Monolog\Logger($settings['name']);
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], Monolog\Logger::DEBUG));
    return $logger;
};
$container['AnimesTable'] = function () {
    return Cake\ORM\TableRegistry::get('Animes', ['className' => 'App\\Model\\Table\\AnimesTable']);
};
ConnectionManager::config($container['settings']['datasources']);
Example #3
0
 * advanced ways of loading plugins
 *
 * Plugin::loadAll(); // Loads all plugins at once
 * Plugin::load('Migrations'); //Loads a single plugin named Migrations
 *
 */
Plugin::load('Migrations');
// Only try to load DebugKit in development mode
// Debug Kit should not be installed on a production system
if (Configure::read('debug')) {
    Plugin::load('DebugKit', ['bootstrap' => true]);
}
/**
 * Connect middleware/dispatcher filters.
 */
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
/**
 * Enable default locale format parsing.
 * This is needed for matching the auto-localized string output of Time() class when parsing dates.
 */
Type::build('date')->useLocaleParser();
Type::build('datetime')->useLocaleParser();
$parametros = Cake\ORM\TableRegistry::get('Parametros');
$findParametros = $parametros->find('all')->all();
if (!empty($findParametros)) {
    foreach ($findParametros as $key => $value) {
        Configure::write('Parametros.' . Inflector::camelize($value->chave), $value->valor);
    }
}