本文整理汇总了PHP中app\App::add方法的典型用法代码示例。如果您正苦于以下问题:PHP App::add方法的具体用法?PHP App::add怎么用?PHP App::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\App
的用法示例。
在下文中一共展示了App::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
// Init database
App::add(function ($req, $res, $next) {
$settings = Config::get('database');
ORM::configure('mysql:host=' . $settings['host'] . ';dbname=' . $settings['dbname']);
ORM::configure('username', $settings['username']);
ORM::configure('password', $settings['password']);
ORM::configure('logging', true);
return $next($req, $res);
});
// Permanently redirect paths with a trailing slash
// to their non-trailing counterpart
App::add(function ($req, $res, $next) {
$uri = $req->getUri();
$path = $uri->getPath();
if ($path != '/' && substr($path, -1) == '/') {
$uri = $uri->withPath(substr($path, 0, -1));
return $res->withRedirect((string) $uri, 301);
}
return $next($req, $res);
});
// Load plugins hooks
// App::add(function($req, $res, $next) {
// $pluginClasses = [
// '\App\Test'
// ];
// foreach ($pluginClasses as $pluginClass) {
// $plugin = new $pluginClass();
// // Check if plugin implements default plugins structure
// if (!$plugin instanceof \App\Core\PluginInterface) {
// $warning = [
// 'pluginClass' => $pluginClass,
示例2:
<?php
namespace App;
use ORM;
// Application middlewares
// CSRF protection
App::add(new \App\Middleware\Csrf());
// Auth infos
App::add(new \App\Middleware\Auth());
// Init database
App::add(function ($req, $res, $next) {
$settings = Config::get('database');
ORM::configure('mysql:host=' . $settings['host'] . ';dbname=' . $settings['dbname']);
ORM::configure('username', $settings['username']);
ORM::configure('password', $settings['password']);
ORM::configure('logging', true);
// Model::$auto_prefix_models = '\\'.$settings['prefix'].'\\';
return $next($req, $res);
});
// Load plugins hooks
// App::add(function($req, $res, $next) {
// $pluginClasses = [
// '\App\Test'
// ];
// foreach ($pluginClasses as $pluginClass) {
// $plugin = new $pluginClass();
// // Check if plugin implements default plugins structure
// if (!$plugin instanceof \App\Core\PluginInterface) {
// $warning = [
// 'pluginClass' => $pluginClass,