本文整理汇总了PHP中Lib::api方法的典型用法代码示例。如果您正苦于以下问题:PHP Lib::api方法的具体用法?PHP Lib::api怎么用?PHP Lib::api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lib
的用法示例。
在下文中一共展示了Lib::api方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$api = Lib::api('admin', array('response' => 'return', 'format' => 'php'));
$type = Req::get('type');
if (!is_callable(array($api, $type))) {
return Lib::redirect('error');
}
$result = $api->{$type}();
$options = array('view' => 'admin');
$ref = Req::post('ref');
if (!$result['state']) {
if (!empty($ref)) {
$options['ref'] = $ref;
}
} else {
$segments = explode('/', base64_decode(urldecode($ref)));
$base = array_shift($segments);
$type = array_shift($segments);
$subtype = array_shift($segments);
if (!empty($type)) {
$options['type'] = $type;
}
if (!empty($subtype)) {
$options['subtype'] = $subtype;
}
}
Lib::redirect('admin', $options);
}
示例2: route
public function route($segments = array())
{
$name = array_shift($segments);
$method = array_shift($segments);
$api = Lib::api($name);
if (!is_callable(array($api, $method))) {
return Lib::api()->fail();
}
$api->{$method}($segments);
}
示例3: route
public static function route()
{
$prefix = '/' . Config::getBaseFolder();
$requesturi = $_SERVER['REQUEST_URI'];
if (substr($requesturi, 0, strlen($prefix)) == $prefix) {
$requesturi = substr($requesturi, strlen($prefix));
}
$requesturi = trim($requesturi, '/');
$requestSegments = explode('?', $requesturi);
$segments = explode('/', $requestSegments[0]);
if ($segments[0] !== 'index.php') {
Lib::load('router');
foreach (Router::getRouters() as $router) {
if (is_string($router->allowedRoute) && $segments[0] !== $router->allowedRoute) {
continue;
}
if (is_array($router->allowedRoute) && !in_array($segments[0], $router->allowedRoute)) {
continue;
}
$router->decode($segments);
}
}
// Check for API call
if (Req::hasget('api')) {
$apiName = Req::get('api');
$action = Req::get('action');
$api = Lib::api($apiName);
if (!is_callable(array($api, $action))) {
return Lib::api()->fail();
}
return $api->{$action}();
}
// Check for controller
if (Req::hasget('controller')) {
$controllerName = Req::get('controller');
$action = Req::get('action');
$controller = Lib::controller($controllerName);
if (!is_callable(array($controller, $action))) {
return $controller->execute();
}
return $controller->{$action}();
}
$viewname = Req::get('view');
if (empty($viewname)) {
$viewname = 'error';
}
return Lib::view($viewname)->display();
}