当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::notFound方法代码示例

本文整理汇总了PHP中Slim\Slim::notFound方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::notFound方法的具体用法?PHP Slim::notFound怎么用?PHP Slim::notFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Slim的用法示例。


在下文中一共展示了Slim::notFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructor
  * 
  * @param \Slim\Slim $app Slim app reference
  */
 public function __construct(\Slim\Slim $app)
 {
     $this->app = $app;
     $this->app->notFound(function () use($app) {
         $data = array('error' => array('message' => 'Invalid route'));
         $app->contentType('application/json');
         $app->halt(400, json_encode($data));
     });
 }
开发者ID:katymdc,项目名称:thermal-api,代码行数:14,代码来源:API_Base.php

示例2: setAssetsRoute

 protected function setAssetsRoute()
 {
     $renderer = $this->debugbar->getJavascriptRenderer();
     $this->app->get('/_debugbar/fonts/:file', function ($file) use($renderer) {
         // e.g. $file = fontawesome-webfont.woff?v=4.0.3
         $files = explode('?', $file);
         $file = reset($files);
         $path = $renderer->getBasePath() . '/vendor/font-awesome/fonts/' . $file;
         if (file_exists($path)) {
             $this->app->response->header('Content-Type', (new \finfo(FILEINFO_MIME))->file($path));
             echo file_get_contents($path);
         } else {
             // font-awesome.css referencing fontawesome-webfont.woff2 but not include in the php-debugbar.
             // It is not slim-debugbar bug.
             $this->app->notFound();
         }
     })->name('debugbar.fonts');
     $this->app->get('/_debugbar/resources/:file', function ($file) use($renderer) {
         $files = explode('.', $file);
         $ext = end($files);
         if ($ext === 'css') {
             $this->app->response->header('Content-Type', 'text/css');
             $renderer->dumpCssAssets();
         } elseif ($ext === 'js') {
             $this->app->response->header('Content-Type', 'text/javascript');
             $renderer->dumpJsAssets();
         }
     })->name('debugbar.resources');
     $this->app->get('/_debugbar/openhandler', function () {
         $openHandler = new OpenHandler($this->debugbar);
         $data = $openHandler->handle($request = null, $echo = false, $sendHeader = false);
         $this->app->response->header('Content-Type', 'application/json');
         $this->app->response->setBody($data);
     })->name('debugbar.openhandler');
 }
开发者ID:Little-Polar-Apps,项目名称:slim-debugbar,代码行数:35,代码来源:DebugBar.php

示例3: pageNotFound

 function pageNotFound($controller, $method)
 {
     return parent::notFound(function () use($controller, $method) {
         $instance = new $controller();
         call_user_func_array(array($instance, $method), array());
     });
 }
开发者ID:fmunoz92,项目名称:mili,代码行数:7,代码来源:Router.php

示例4: setupNotFound

 /**
  * @return $this
  */
 protected function setupNotFound()
 {
     $app = $this->app;
     $this->app->notFound(function () use($app) {
         $app->render('404.phtml');
     });
     return $this;
 }
开发者ID:stuartmclean,项目名称:my_website,代码行数:11,代码来源:SlimApp.php

示例5: __construct

 public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null)
 {
     $this->setOptions($options);
     $this->app = $app;
     $this->client = $client;
     $this->schema = new Schema($client);
     if ($theme) {
         $this->setTheme($theme);
     }
     if ($this->hasOption('upload.directory')) {
         $this->setUploadDirectory($this->getOption('upload.directory'));
     }
     // Set up the home route.
     $app->get('/', Closure::bind(function () {
         $controller = new Controllers\HomeController($this->app, $this->schema, $this->client);
         $controller->read();
     }, $this));
     // Set up the uploads route.
     $app->get($this->getOption('path.format.uploads'), Closure::bind(function ($file_name) {
         $controller = new Controllers\UploadController($this->app);
         $controller->read($file_name);
     }, $this));
     // Set up the search controller.
     $app->get($this->getOption('path.format.search'), Closure::bind(function () {
         $controller = new Controllers\SearchController($this->app, $this->schema, $this->client);
         $controller->run();
     }, $this))->name('search');
     // Set up the resources controller.
     $this->app->get($this->getOption('path.format.resources'), Closure::bind(function (array $resource_path) {
         $theme = $this->getTheme();
         // Pass if not an instance or child of the default theme, as Theme#renderResource won't be present.
         // In non-standard use cases, this allows the user to use a regular Slim\View as the view.
         if (!$theme) {
             $this->getApp()->pass();
         }
         $controller = new Controllers\FileController($this->app);
         if ($theme->hasResource($resource_path)) {
             $controller->read($theme->getResourcePath($resource_path));
         } else {
             $this->getApp()->notFound(new Exceptions\Exception('Unknown resource "' . implode('/', $resource_path) . '".'));
         }
     }, $this))->name('resources');
     // Set up a default handler for 404 errors.
     // Only Penelope application-generated exceptions are permitted.
     $app->notFound(function (Exceptions\Exception $e = null) {
         if (!$e) {
             $e = new Exceptions\NotFoundException('The requested page cannot be found.');
         }
         $controller = new Controllers\Controller($this->app);
         $this->app->render('error', array('title' => $controller->_m('error_404_title'), 'error' => $e), 404);
     });
 }
开发者ID:karwana,项目名称:penelope,代码行数:52,代码来源:Penelope.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param array $options The SameAs Lite Store for which we shall
  * provide RESTful interfaces.
  */
 public function __construct(array $options = array())
 {
     // fake $_SERVER parameters if required (eg command line invocation)
     \SameAsLite\Helper::initialiseServerParameters();
     // set the default format of acceptable parameters
     // see http://docs.slimframework.com/routing/conditions/#application-wide-route-conditions
     \Slim\Route::setDefaultConditions(array('store' => '[a-zA-Z0-9_\\-\\.]+'));
     // initialise and configure Slim, using Twig template engine
     $mode = isset($options['mode']) ? $options['mode'] : 'production';
     $this->app = new \Slim\Slim(array('mode' => $mode, 'debug' => false, 'view' => new \Slim\Views\Twig()));
     // configure Twig
     $this->app->view()->setTemplatesDirectory('assets/twig/');
     $this->app->view()->parserOptions['autoescape'] = false;
     $this->app->view()->set('path', $this->app->request()->getRootUri());
     // register 404 and custom error handlers
     $this->app->notFound(array(&$this, 'outputError404'));
     $this->app->error(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     set_exception_handler(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     // Hook to set the api path
     $this->app->hook('slim.before.dispatch', function () {
         // fix api pages such that if viewing a particular store
         // then the store name is automatically injected for you
         $params = $this->app->router()->getCurrentRoute()->getParams();
         if (isset($params['store'])) {
             $apiPath = "datasets/{$params['store']}/api";
         } else {
             $apiPath = 'api';
         }
         $this->app->view()->set('apiPath', $apiPath);
     });
     // save the options
     $this->appOptions = $options;
     // apply options to template
     foreach ($options as $k => $v) {
         $this->app->view->set($k, $v);
     }
 }
开发者ID:joetm,项目名称:sameAs-Lite,代码行数:45,代码来源:WebApp.php

示例7: addRouteDefinitions

 /**
  * This methods will be called at application startup
  * @param $appInstance
  * @return void
  * @throws \Exception
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) {
         if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) {
             $appInstance->halt(400, 'Invalid request');
         }
         $fileName = array_pop($path);
         $rel = '';
         foreach ($path as $value) {
             $rel .= $value . '/';
         }
         $rel .= $fileName;
         $user = null;
         if ($accessMethod === 'private') {
             try {
                 $user = new MembersAuth();
                 $user->isUserLoggedIn();
             } catch (LoginExceptions $e) {
                 $appInstance->halt(401, 'Unauthorized');
             }
         }
         $fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel;
         $controller = new cProtectedStorage($inst, $id, $accessMethod, $rel);
         if ($controller->isCorrectPath($fullPath)) {
             $appInstance->etag(md5($fullPath));
             $appInstance->expires('+1 week');
             $headers = $controller->outputFile();
             if (array_key_exists('download', $_REQUEST)) {
                 $headers['Content-Type'] = 'application/octet-stream';
             }
             foreach ($headers as $key => $value) {
                 $appInstance->response->headers->set($key, $value);
             }
         } else {
             $appInstance->notFound();
         }
     })->via('GET', 'POST');
 }
开发者ID:indiwine,项目名称:EMA-engine,代码行数:44,代码来源:ProtectedStorageRouting.php

示例8: function

$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);
});
// ==================================================================
//
//  Cookies advise
//
// ------------------------------------------------------------------
$data['cookieState'] = !isset($_COOKIE[$data['cookies']['name']]) ? true : false;
// ==================================================================
//
//  Add before.dispatch and run app
//
开发者ID:sond3,项目名称:sliminit,代码行数:32,代码来源:core.php

示例9: attach

 /**
  * @param Slim $slim
  *
  * @return void
  */
 public function attach(Slim $slim)
 {
     // Register Global Exception Handler
     $slim->notFound([$this, 'handleNotFound']);
     // Register Global Exception Handler
     $slim->error([$this, 'handleException']);
 }
开发者ID:GreatOwl,项目名称:mcp-panthor,代码行数:12,代码来源:ErrorHandler.php

示例10: function

$app->put('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->put();
    }
});
// Delete
$app->delete('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->delete();
    }
});
// Options
$app->options('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->options();
    }
});
// Not found
$app->notFound(function () {
    Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
});
$app->run();
开发者ID:rohanabraham,项目名称:lxHive,代码行数:31,代码来源:index.php

示例11: Slim

}
$app = new Slim(['mode' => $slimMode, 'debug' => $debug, 'view' => $di->layoutHtml]);
// Allow to decode json request body
$app->add(new ContentTypesMiddleware());
$app->get('/auth/login', function () use($app) {
    $app->render('auth/login');
});
$app->get('/auth/twitter/login', function () {
    AuthTwitterController::getInstance()->login();
});
$app->get('/auth/twitter/callback', function () {
    AuthTwitterController::getInstance()->callback();
});
$app->get('/auth/logout', function () {
    AuthentifierController::getInstance()->logout();
});
$app->get('/home', function () {
    HomeController::getInstance()->home();
});
$app->get('/api/articles', function () {
    ArticlesController::getInstance()->get();
});
$app->patch('/api/articles/:id', function ($id) {
    ArticlesController::getInstance()->update($id);
});
$app->notFound(function () use($app) {
    $status = 404;
    $app->response->setStatus($status);
    $app->render('error', ['errno' => $status, 'message' => $app->response->getMessageForCode($status)]);
});
return $app;
开发者ID:petitchevalroux,项目名称:newswatcher-www,代码行数:31,代码来源:slim.php

示例12: function

/**
* LEGACY REDIRECT
**/
$app->get('/redeem/redeem.php?c=:code&p=:album', function ($album, $code) use($app) {
    $app->redirect('./redeem/' . $album . '/' . $code);
});
/**
* Album Download page
**/
$app->get('/download/:album/:code', function ($album, $code) use($app, $dl) {
    $download = $dl->file_download($album, $code);
    $dl->use_code($code, $album);
})->name('download');
// Custom 404 Page
$app->notFound(function () use($app) {
    $app->render('notfound.twig');
});
// Temporary Admin Page
$app->get('/webhook/', function () use($app) {
    $app->response->setStatus(200);
});
// Temporary Admin Page
$app->post('/webhook/', function () use($app, $dl) {
    $app->response->setStatus(200);
    $wh = json_decode($app->request->post('mandrill_events'), true);
    foreach ($wh as $event) {
        $sent_time = date("Y-m-d H:i:s", $event['msg']['ts']);
        $event_time = date("Y-m-d H:i:s", $event['ts']);
        $state = $event['msg']['state'];
        $id = $event['msg']['_id'];
        $email = $event['msg']['email'];
开发者ID:nblakefriend,项目名称:download,代码行数:31,代码来源:index.php

示例13: Slim

use Slim\Slim;
require 'includes/classmap.php';
require 'Vendor/autoload.php';
spl_autoload_register('autoloadlitpi');
//Init slim object
$app = new Slim();
/////////////////////////
///// Important, process to include controller file
///This is the main different with LITPI framework core
//Parsing route information to include module/controller
$route = trim($app->request->getPathInfo(), '/');
$parts = explode('/', $route);
for ($i = 0; $i < count($parts); $i++) {
    $parts[$i] = htmlspecialchars($parts[$i]);
}
$module = array_shift($parts);
$controller = array_shift($parts);
$action = array_shift($parts);
$class = '\\controller\\' . $module . '\\' . $controller;
//check if valid controller
if (classmap($class) != '') {
    /** @var \Controller\BaseController $myControllerObj */
    $myControllerObj = new $class($app);
    $myControllerObj->run();
} else {
    $app->notFound(function () use($app) {
        echo 'Not found';
    });
}
$app->run();
开发者ID:voduytuan,项目名称:php-restful-mockery,代码行数:30,代码来源:index.php

示例14: Slim

<?php

use ComPHPPuebla\Slim\Hook\PhpSettingsHook;
use ComPHPPuebla\Slim\Handler\ErrorHandler;
use ComPHPPuebla\Slim\Handler\NotFoundHandler;
use ComPHPPuebla\Slim\Middleware\JsonpMiddleware;
use ComPHPPuebla\Slim\Middleware\ContentNegotiationMiddleware;
use ComPHPPuebla\Slim\Middleware\HttpCacheMiddleware;
use Slim\Slim;
use Api\Station\StationRoutes;
use Api\ApplicationContainer;
use Api\Station\StationContainer;
chdir(__DIR__);
require 'vendor/autoload.php';
$app = new Slim(require 'config/app.config.php');
$app->notFound(new NotFoundHandler($app));
$app->error(new ErrorHandler($app));
$app->hook('slim.before', new PhpSettingsHook(require 'config/phpini.config.php'));
$container = new ApplicationContainer();
$container->register($app);
$app->add(new HttpCacheMiddleware($app->cache));
$app->add(new ContentNegotiationMiddleware());
$app->add(new JsonpMiddleware());
$stationContainer = new StationContainer();
$stationContainer->register($app);
$stationRoutes = new StationRoutes($app);
$stationRoutes->register();
开发者ID:comphppuebla,项目名称:echale-gas-api,代码行数:27,代码来源:application.php

示例15: checkRoute

 protected function checkRoute($controllerName, $action)
 {
     if (is_callable(array($controllerName, $action)) === false) {
         $this->app->notFound();
     }
 }
开发者ID:benconnito,项目名称:kopper,代码行数:6,代码来源:FrontController.php


注:本文中的Slim\Slim::notFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。