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


PHP Slim\Slim类代码示例

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


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

示例1: inscription

 public function inscription(\Slim\Slim $app)
 {
     $allPostVars = $app->request->post();
     $username = $allPostVars['username'];
     $mail = $allPostVars['mail'];
     $mdp = $allPostVars['mdp'];
     try {
         $db = getDB();
         $verif = $db->prepare("SELECT username \n\t\t\t\tFROM users\n\t\t\t\tWHERE username = :username");
         $verif->bindParam(':username', $username, PDO::PARAM_INT);
         $verif->execute();
         $usernamed = $verif->fetch(PDO::FETCH_OBJ);
         $verif->closeCursor();
         if ($usernamed) {
             $answer = "Ce nom d'utilisateur est déjà pris, merci de retenter avec un nouveau.";
         } else {
             $sth = $db->prepare("INSERT INTO users \n\t\t\t\t(username, mail, mdp)\n\t\t\t\tVALUES (:username, :mail, :mdp)");
             $sth->bindParam(':username', $username, PDO::PARAM_INT);
             $sth->bindParam(':mail', $mail, PDO::PARAM_INT);
             $sth->bindParam(':mdp', $mdp, PDO::PARAM_INT);
             $sth->execute();
             $answer = array("status" => "success", "code" => 1);
         }
         $app->response->setStatus(200);
         $app->response()->headers->set('Content-Type', 'application/json');
         echo json_encode($answer);
         $db = null;
     } catch (PDOException $e) {
         $app->response()->setStatus(404);
         echo '{"error":{"text":' . $e->getMessage() . '}}';
     }
 }
开发者ID:antoninriviere,项目名称:slimrest,代码行数:32,代码来源:class-connexion.php

示例2: Delete

 public function Delete($files, \Slim\Slim &$app, $page)
 {
     $obj = new Files();
     $obj->parseFile($files);
     $user_id = $obj->user_id;
     //$cookieDB = $obj->cookie;
     $cookie = $app->getCookie('username');
     $db = $app->db;
     $logged = new Logged();
     $id = $logged->getLogged($db, $cookie);
     //checking of the user is registered in Users table as the user or anonymous which added this file and getting his id
     if ($id == $user_id) {
         $foo = new Foo();
         $foo->token = $page;
         $mapper = new FooMapper($db);
         $files = $mapper->delete($foo);
         $path = $obj->path;
         $filename = "uploads/" . $path;
         //deleting file from the folder
         unlink($filename);
         $app->redirect('/TwigBlog/');
     } else {
         $app->error();
     }
 }
开发者ID:toppestkek,项目名称:TwigBlog,代码行数:25,代码来源:Checkrights.php

示例3: refresh

 /**
  * Load config into slim configuration
  * @param Slim $app
  */
 public function refresh(Slim $app = null)
 {
     if ($app != null) {
         $this->app = $app;
     }
     $this->app->config($this->config);
 }
开发者ID:nogo,项目名称:framework,代码行数:11,代码来源:SlimLoader.php

示例4: setup

 /**
  * Setup the form service.
  *
  * @param \Slim\Slim $app The application instance.
  */
 public static function setup(Slim $app)
 {
     $app->container->singleton('form', function () use($app) {
         $prefix = $app->config('form.prefix');
         return new Form($prefix ?: null);
     });
 }
开发者ID:creativeduo,项目名称:thin,代码行数:12,代码来源:Form.php

示例5: loginUser

function loginUser(\Slim\Slim $slimApp)
{
    //echo "middleware:loginUser";
    $request = $slimApp->request;
    $response = $slimApp->response();
    $response->headers->set('Content-Type', 'application/json');
    //
    $userData = json_decode($request->getBody());
    $name = $userData->userName;
    $password = $userData->password;
    $email = $userData->email;
    //
    $dbUtil = new \icraft\DBUtil();
    $DBH = $dbUtil->getConnection();
    // $sql = "SELECT * FROM `users` WHERE uName=\'saumya\' && uPassword=\'saumyaPW1\'";
    //$STH = $DBH->prepare("SELECT * FROM `users` WHERE uName='$name' && uPassword='$password'");
    $STH = $DBH->query("SELECT * FROM `users` WHERE uName='{$name}' && uPassword='{$password}'");
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    //$STH->execute();
    //var_dump($STH);
    $response->body('FAIL');
    // Default FAIL
    while ($row = $STH->fetch()) {
        /*
        echo $row['uName'] . "\n";
        echo $row['uPassword'] . "\n";
        echo $row['uEmail'] . "\n";
        */
        $n = $row['uName'];
        $p = $row['uPassword'];
        $e = $row['uEmail'];
        $responseObj = "{'status':'SUCCESS','userObj':{'name':{$n},'password':{$p},'email':{$e}}}";
        $response->body($responseObj);
    }
}
开发者ID:saumya,项目名称:slimCraft,代码行数:35,代码来源:middleWare.php

示例6: addRouteDefinitions

 /**
  * This methods will be called at application startup
  * @param $appInstance
  * @return void
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->post('/ajax', function () use(&$appInstance) {
         $exceptionContentType = 'text/plain';
         $appInstance->response->headers->set('Cache-Control', 'no-store');
         try {
             $contentType = EmaRpcApi::slimCallback($appInstance);
             $appInstance->response->headers->set('Content-Type', $contentType);
         } catch (SecurityException $e) {
             $appInstance->response->setStatus(401);
             $appInstance->response->headers->set('Content-Type', $exceptionContentType);
             print "Unauthorized.\n" . $e->getMessage();
         } catch (\RuntimeException $e) {
             $appInstance->response->setStatus(400);
             $appInstance->response->headers->set('Content-Type', $exceptionContentType);
             print $e->getMessage();
             $logger = new DbLogger();
             $logger->writeException($e);
         } catch (\Exception $e) {
             $logger = new DbLogger();
             $logger->writeException($e);
             $appInstance->response->setStatus(500);
             $appInstance->response->headers->set('Content-Type', $exceptionContentType);
             $msg = "Server Error Occurred. Please contact us. Error code is: " . $e->getCode();
             if (EMA_DEBUG === true) {
                 $msg = $e->getMessage() . ";\n Code: " . $e->getCode() . "\n\n\n" . $e->getTraceAsString();
             }
             print $msg;
         }
     });
     if (EMA_REST_API) {
         $appInstance->map('/rest/:path+', function ($path) use($appInstance) {
             $appInstance->response->headers->set('Cache-Control', 'no-store');
             $appInstance->response->headers->set('Content-Type', 'application/json');
             $printoutError = function (\Exception $e, $status = 500) use($appInstance) {
                 $appInstance->response->setStatus($status);
                 print EmaRestApi::getErrorOutput($e);
             };
             try {
                 $rpc = EmaRestApi::rpcFactory($path, $appInstance->request->getMethod(), $appInstance);
                 $result = EmaRestApi::rpcCheckAndRun($rpc, $appInstance);
                 if (EmaRestApi::$isAddition) {
                     $appInstance->response->setStatus(201);
                     $appInstance->response->headers->set('Location', EmaRestApi::$additionRouteBase);
                 }
                 print json_encode($result);
             } catch (InputError $e) {
                 $printoutError($e, 400);
             } catch (SecurityException $e) {
                 $printoutError($e, 403);
             } catch (NotFound $e) {
                 $printoutError($e, 404);
             } catch (Unsupported $e) {
                 $printoutError($e, 415);
             } catch (\Exception $e) {
                 $printoutError($e, 500);
             }
         })->via('GET', 'POST', 'DELETE');
     }
 }
开发者ID:indiwine,项目名称:EMA-engine,代码行数:65,代码来源:ApiRoutes.php

示例7: openDatabase

 /**
  * Open a database connection
  *
  * @param \Slim\Slim $app
  * @return \PDO
  */
 public static function openDatabase($app)
 {
     $dsn = $app->config('database.dsn');
     $user = $app->config('database.user');
     $pass = $app->config('database.pass');
     return new \PDO($dsn, $user, $pass);
 }
开发者ID:blueskyfish,项目名称:temperature-monitor,代码行数:13,代码来源:DB.php

示例8: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     // Capture STDOUT
     ob_start();
     $options = array('REQUEST_METHOD' => strtoupper($method), 'PATH_INFO' => $path, 'SERVER_NAME' => 'local.dev');
     if ($method === 'get') {
         $options['QUERY_STRING'] = http_build_query($data);
     } elseif (is_array($data)) {
         $options['slim.input'] = http_build_query($data);
     } else {
         $options['slim.input'] = $data;
     }
     // Prepare a mock environment
     Slim\Environment::mock(array_merge($options, $optionalHeaders));
     $env = Slim\Environment::getInstance();
     $this->app->router = new NoCacheRouter($this->app->router);
     $this->app->request = new Slim\Http\Request($env);
     // Custom headers
     $this->app->request->headers = new Slim\Http\Headers($env);
     $this->app->response = new Slim\Http\Response();
     // Establish some useful references to the slim app properties
     $this->request = $this->app->request();
     $this->response = $this->app->response();
     // Execute our app
     $this->app->run();
     // Return the application output. Also available in `response->body()`
     return ob_get_clean();
 }
开发者ID:hochanh,项目名称:slim-test-helpers,代码行数:28,代码来源:WebTestClient.php

示例9: configureModes

 public static function configureModes(Slim $app, array $modeConfigs)
 {
     foreach ($modeConfigs as $mode => $config) {
         $app->configureMode($mode, function () use($app, $config) {
             $app->config($config);
         });
     }
 }
开发者ID:fousheezy,项目名称:slim-core,代码行数:8,代码来源:Mode.php

示例10: configure

 /**
  * Configure the middleware layers for your application
  *
  * @param Slim $app
  */
 public function configure(Slim $app)
 {
     $this->init($app->container);
     /** @var MiddlewareProvider $middleware */
     foreach ($this->middleware as $middleware) {
         $app->add($middleware);
     }
 }
开发者ID:comphppuebla,项目名称:slim-modules,代码行数:13,代码来源:MiddlewareLayers.php

示例11: setUp

 public function setUp()
 {
     parent::setUp();
     $app = new Slim();
     $app->get('/test', function () {
     })->name('test');
     $this->ext = new Xhgui_Twig_Extension($app);
 }
开发者ID:perftools,项目名称:xhgui,代码行数:8,代码来源:ExtensionTest.php

示例12: configure

 /**
  * @param Slim $slim
  *
  * @return null
  */
 public function configure(Slim $slim)
 {
     foreach ($this->hooks as $event => $hooks) {
         foreach ($hooks as $hook) {
             $slim->hook($event, $this->hookClosure($slim, $hook));
         }
     }
 }
开发者ID:GreatOwl,项目名称:mcp-panthor,代码行数:13,代码来源:SlimConfigurator.php

示例13: __construct

 /**
  * constructor
  */
 final function __construct()
 {
     self::$app || (self::$app = \Slim\Slim::getInstance());
     $this->request = self::$app->request();
     $this->response = self::$app->response();
     $this->config = self::$app->config;
     $this->validator = self::$app->validator;
     $this->init();
 }
开发者ID:donghaichen,项目名称:Clover,代码行数:12,代码来源:BaseController.php

示例14: __construct

 public function __construct(StorageInterface $storage, Slim $app)
 {
     $this->storage = $storage;
     $this->app = $app;
     $this->ignored = $app->config('api.classes.auth.ignored');
     if (!is_array($this->ignored)) {
         $this->ignored = array();
     }
 }
开发者ID:dwsla,项目名称:deal,代码行数:9,代码来源:Deal.php

示例15: addServices

 /**
  * Adds services to the Statical Manager
  *
  * @param \Statical\Manager $manager
  * @param \Slim\Slim $slim
  */
 protected static function addServices($manager, $slim)
 {
     $services = array('Input' => 'request', 'Request' => 'request', 'Response' => 'response', 'View' => 'template');
     $container = $slim->getContainer();
     foreach ($services as $alias => $id) {
         $proxy = __NAMESPACE__ . '\\' . $alias;
         $manager->addProxyService($alias, $proxy, $container, $id);
     }
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:15,代码来源:SlimStatic.php


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