本文整理汇总了PHP中Slim\Slim::group方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::group方法的具体用法?PHP Slim::group怎么用?PHP Slim::group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::group方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRouteDefinitions
/**
* Adds a backend routes
* @param $appInstance
* @return void
*/
public static function addRouteDefinitions(Slim $appInstance)
{
$appInstance->group('/admin', function () use($appInstance) {
$appInstance->get('/', function () {
print '<h1>A Simple Backend</h1>';
});
$appInstance->map("/chpass", function () use($appInstance) {
if (EMA_ADMIN_CHPASS) {
AdminPasswordChange_controller::process();
} else {
$appInstance->pass();
}
})->via('GET', 'POST');
$appInstance->map("/update", function () use($appInstance) {
ClassAndMethodsDispatcher::updateGPMethods();
})->via('GET', 'POST');
$appInstance->post("/login", function () use($appInstance) {
$appInstance->response->headers->set('Cache-Control', 'no-store');
if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) {
try {
try {
$user = new UserAuth();
} catch (SessionExpired $e) {
$user = new UserAuth();
}
$user->userLogin($_POST['username'], $_POST['password']);
if (!$user->isAdmin()) {
$user->logout();
throw new LoginIncorrect('You are not allowed to login here');
}
$appInstance->response->headers->set('Content-Type', 'application/json');
print json_encode($user->getSessionAuthData());
} catch (LoginIncorrect $e) {
$appInstance->response->headers->set('Content-Type', 'text/plain');
$appInstance->response->setStatus(400);
print $e->getMessage();
}
} else {
$appInstance->response->headers->set('Content-Type', 'text/plain');
$appInstance->response->setStatus(400);
print 'Bad request';
}
});
$appInstance->map('/logout', function () use($appInstance) {
try {
$user = new UserAuth();
if ($user->isUserLoggedInSimple()) {
$user->logout();
}
} catch (SessionExpired $e) {
}
})->via('GET', 'POST');
});
}
示例2: addRouteDefinitions
/**
* This methods will be called at application startup
* @param $appInstance
* @return void
*/
public static function addRouteDefinitions(Slim $appInstance)
{
$appInstance->group('/nats', function () use($appInstance) {
$appInstance->map('/users', function () use($appInstance) {
try {
$inst = new cNatsMembersPostback();
print 'OK|' . $inst->run();
} catch (InputError $e) {
print 'NOTOK|' . $e->getMessage();
} catch (FatalError $e) {
print 'ERROR|' . $e->getMessage();
}
})->via('GET', 'POST');
});
}
示例3: add
/**
* @param string $routeName
* @param string $tableName
* @param callable $customCRUDFunction
* @param string $displayName
*/
public function add($routeName, $customCRUDFunction = null, $tableName = null, $displayName = null)
{
if ($tableName == null) {
$tableName = $routeName;
}
$this->tableList[$routeName] = $tableName;
$this->tableDisplayName[$routeName] = $displayName;
$this->routeNameList[] = $routeName;
/*
* Page Group (ListView, CreateView, EditView)
*/
$this->slim->group("/" . $this->groupName . "/" . $routeName, function () use($routeName, $customCRUDFunction, $tableName) {
$this->slim->get("/", function () use($routeName) {
$this->slim->redirectTo("_louisCRUD_" . $routeName);
});
/*
* ListView
*/
$this->slim->get("/list(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
// MUST INIT FIRST
$this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
if ($this->configFunction != null) {
$function = $this->configFunction;
$result = $function();
if ($result === false) {
return;
}
}
if ($customCRUDFunction != null) {
$result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
if ($result === false) {
return;
}
}
if ($this->listviewFunction != null) {
$listviewFunction = $this->listviewFunction;
$result = $listviewFunction($p1, $p2, $p3, $p4, $p5);
if ($result === false) {
return;
}
}
if ($this->isEnabledListView()) {
$this->renderListView();
}
})->name("_louisCRUD_" . $routeName);
/*
* Create
*/
$this->slim->get("/create(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
// MUST INIT FIRST
$this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
if ($this->configFunction != null) {
$function = $this->configFunction;
$result = $function();
if ($result === false) {
return;
}
}
if ($customCRUDFunction != null) {
$result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5);
if ($result === false) {
return;
}
}
if ($this->createFunction != null) {
$createFunction = $this->createFunction;
$result = $createFunction($p1, $p2, $p3, $p4, $p5);
if ($result === false) {
return;
}
}
// Force Hide ID field
$this->field("id")->hide();
if ($this->isEnabledCreate()) {
$this->renderCreateView();
}
});
/*
* Edit
*/
$this->slim->get("/edit/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) {
// MUST INIT FIRST
$this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5);
// Load Bean first
$this->loadBean($id);
// ID must be hidden
$this->field("id")->hide();
if ($this->configFunction != null) {
$function = $this->configFunction;
$result = $function();
if ($result === false) {
return;
}
}
//.........这里部分代码省略.........
示例4: configureRoutes
/**
* Configure routes to be handled by application.
*
* @param \Slim\Slim $slim Application
*/
protected function configureRoutes(\Slim\Slim $slim)
{
$slim->group('/', function () use($slim) {
App::template($slim, 'about');
$slim->get('projects', function () use($slim) {
$page = new Pages\Projects($slim);
$page->setI18nContext($slim->i18nContext);
$page->setLogs($slim->logs);
$page();
})->name('projects');
$slim->get('log/:id', function ($id) use($slim) {
$page = new Pages\Log($slim);
$page->setI18nContext($slim->i18nContext);
$page->setLogs($slim->logs);
$page($id);
})->name('log');
$slim->get('(:project)', function ($project = 'production') use($slim) {
$page = new Pages\Sal($slim);
$page->setI18nContext($slim->i18nContext);
$page->setLogs($slim->logs);
$page($project);
})->name('SAL');
});
// end group '/'
$slim->notFound(function () use($slim) {
$slim->render('404.html');
});
}
示例5: configureRoutes
/**
* Configure routes to be handled by application.
*
* @param \Slim\Slim $slim Application
*/
protected function configureRoutes(\Slim\Slim $slim)
{
$middleware = array('must-revalidate' => function () use($slim) {
$slim->response->headers->set('Cache-Control', 'private, must-revalidate, max-age=0');
$slim->response->headers->set('Expires', 'Thu, 01 Jan 1970 00:00:00 GMT');
}, 'inject-user' => function () use($slim) {
$user = $slim->authManager->getUserData();
$slim->view->set('user', $user);
}, 'require-user' => function () use($slim) {
if ($slim->authManager->isAnonymous()) {
if ($slim->request->isGet()) {
$uri = $slim->request->getUrl() . $slim->request->getPath();
$qs = Form::qsMerge();
if ($qs) {
$uri = "{$uri}?{$qs}";
}
$_SESSION[AuthManager::NEXTPAGE_SESSION_KEY] = $uri;
}
// FIXME: use i18n
$slim->flash('error', 'Login required');
$slim->flashKeep();
$slim->redirect($slim->urlFor('login'));
}
});
$slim->group('/', $middleware['inject-user'], function () use($slim, $middleware) {
App::redirect($slim, '', 'random', 'home');
App::redirect($slim, 'index', 'random');
$slim->get('random', function () use($slim) {
$page = new Pages\Random($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page();
})->name('random');
$slim->get('random.json', function () use($slim) {
$slim->response->headers->set('Content-Type', 'application/json');
$page = new Pages\Random($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page->setTemplate('random.json');
$page();
})->name('random.json');
$slim->get('search', function () use($slim) {
$page = new Pages\Search($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page();
})->name('search');
$slim->get('top', function () use($slim) {
$page = new Pages\Top($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page();
})->name('top');
App::template($slim, 'login');
$slim->get('logout', $middleware['must-revalidate'], function () use($slim) {
$slim->authManager->logout();
$slim->redirect($slim->urlFor('home'));
})->name('logout');
App::template($slim, 'about');
App::template($slim, 'help');
});
// end group '/'
$slim->group('/quip/', $middleware['inject-user'], function () use($slim, $middleware) {
$slim->get(':id', function ($id) use($slim) {
$page = new Pages\Quip($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page($id);
})->name('quip');
$slim->get(':id/edit', $middleware['require-user'], function ($id) use($slim) {
$page = new Pages\Edit($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page($id);
})->name('edit');
$slim->post(':id/post', $middleware['require-user'], function ($id) use($slim) {
$page = new Pages\Edit($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page($id);
})->name('edit_post');
$slim->post(':id/delete', $middleware['require-user'], function ($id) use($slim) {
$page = new Pages\Delete($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page($id);
})->name('delete_post');
$slim->post(':id/vote', $middleware['require-user'], function ($id) use($slim) {
$page = new Pages\Vote($slim);
$page->setI18nContext($slim->i18nContext);
$page->setQuips($slim->quips);
$page($id);
})->name('vote_post');
});
$slim->group('/oauth/', function () use($slim) {
//.........这里部分代码省略.........
示例6: function
$app->group('/emojis', function () use($app) {
/**
* View all emojis
*/
$app->get('/', function () use($app) {
return EmojiController::getAll($app);
});
/**
* Find emoji by id
*/
$app->get('/:id', function ($id) use($app) {
return EmojiController::find($app, $id);
});
/**
* Create new emoji
*/
$app->post('/', function () use($app) {
return EmojiController::create($app);
});
/**
* Update an emoji
*/
$app->put('/:id', function ($id) use($app) {
return EmojiController::update($app, $id);
});
$app->patch('/:id', function ($id) use($app) {
return EmojiController::update($app, $id);
});
/**
* delete an emoji
*/
$app->delete('/:id', function ($id) use($app) {
return EmojiController::delete($app, $id);
});
/**
* extra (fetch emoji by any criteria)
*/
$app->get('/:field/:criteria', function ($field, $criteria) use($app) {
return EmojiController::findBy($app, $field, $criteria);
});
});
示例7: function
if (in_array($lang_uri, $data['app_langs'])) {
if ($lang_uri != $data['default_lang']) {
$data['lang'] = $lang_uri;
$route = '/' . $lang_uri;
$home_link = $route;
}
}
$data['home_link'] = $home_link;
$data['langs'] = (require '../app/langs/' . $data['lang'] . '.php');
$pages = (require '../app/config/pages.php');
$lang = $data['lang'];
$data['route'] = function ($routeName) use($pages, $lang, $route) {
return $route . $pages[$routeName][$lang]['route'];
};
$app->group($route, function () use($app, $data, $pages) {
require '../app/routes/site.php';
});
// ==================================================================
//
// Errors 404 and 500
//
// ------------------------------------------------------------------
$app->notFound(function () use($app) {
$data['metas']['title'] = '404 Page not Found';
$app->render('404', $data);
});
$app->error(function () use($app) {
$data['metas']['title'] = 'Internal server error';
$app->render('500', $data);
});
// ==================================================================
示例8: function
}
if (!$b) {
$app = \Slim\Slim::getInstance();
$app->flash('msgError', 'Login requerido');
$app->redirect(URL . 'login');
}
} else {
$app = \Slim\Slim::getInstance();
$app->flash('msgError', 'Login requerido');
$app->redirect(URL . 'login');
}
};
}
$app->config(array('templates.path' => 'app/view/'));
$app->group('/', function () use($app) {
$app->get('/', function () use($app) {
});
});
$app->group('/login', function () use($app) {
$app->get('/', function () use($app) {
$app->render('login.php');
});
$app->post('/', function () use($app) {
$data = $app->request()->post();
$login = new LoginController();
$result = $login->login($data);
if ($result) {
$app->flash('msgInfo', 'Bienvenido ' . $_SESSION['user']);
if ($_SESSION['tipo'] == 1) {
$app->redirect(URL . 'pacientes');
}
if ($_SESSION['tipo'] == 2) {