slim

Slim Framework 2.0.0 Unable to use ->params() with GET

假如想象 提交于 2020-01-06 06:45:53
问题 I'm using SLIM 2.0.0 Is it possible to use ->params() with GET? In the example below if I call it by POST: curl -d "param1=hello&param2=world" http://localhost/foo it prints: helloworld CORRECT!! if I call it by GET: http://localhost/foo/hello/world it prints: NOTHING!! <- WRONG!! Why? <?php require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app -> get('/foo/:param1/:param2', 'foo'); $app -> post('/foo', 'foo'); $app -> run(); function foo() { $request =

Optional parameters on index route

时间秒杀一切 提交于 2020-01-06 02:53:08
问题 I have a very simple application where I intend to optionally accept a parameter on the index route such that the user can either go to http://example.com/ or http://example.com/somethingrandom I wish to be able to capture the somethingrandom as an optional parameter but I am having no luck. Here is my route: $app -> get('/(:random)', function($random=null) use($app) { ... do some stuff }); 回答1: According to the Slim documentation, the / needs to be inside the parentheses. So try: $app -> get

Slim framework Message: Callable Homecontroller does not exist

感情迁移 提交于 2020-01-05 07:47:12
问题 Project Structure public/index.php <?php require __DIR__ . '/../vendor/autoload.php'; ini_set('display_errors', 'On'); if (PHP_SAPI == 'cli-server') { // To help the built-in PHP dev server, check if the request was actually for // something which should probably be served as a static file $url = parse_url($_SERVER['REQUEST_URI']); $file = __DIR__ . $url['path']; if (is_file($file)) { return false; } } session_start(); // Instantiate the app $settings = require __DIR__ . '/../src/settings.php

Slim framework Message: Callable Homecontroller does not exist

ぃ、小莉子 提交于 2020-01-05 07:47:06
问题 Project Structure public/index.php <?php require __DIR__ . '/../vendor/autoload.php'; ini_set('display_errors', 'On'); if (PHP_SAPI == 'cli-server') { // To help the built-in PHP dev server, check if the request was actually for // something which should probably be served as a static file $url = parse_url($_SERVER['REQUEST_URI']); $file = __DIR__ . $url['path']; if (is_file($file)) { return false; } } session_start(); // Instantiate the app $settings = require __DIR__ . '/../src/settings.php

Calling an internal api within another api in using Slim Framework

混江龙づ霸主 提交于 2020-01-04 19:06:48
问题 Good day, Im trying to develop a web platform using Slim framework. I've done it in MVC way. some of my APIs are used to render the view and some is just built to get data from the db. for example : $app->get('/api/getListAdmin', function () use ($app) { $data = ...//code to get admins' list echo json_encode($data); })->name("getListAdmin"); $app->get('/adminpage', function () use ($app) { // **** METHOD 1 :// get the data using file_get_contents $result = file_get_contents(APP_ROOT.'api

Slim + Twig - how to turn off Twig cache during development?

ぃ、小莉子 提交于 2020-01-04 03:44:07
问题 This is the view which is twig that I inject it in the container in Slim: // Views and Templates // https://www.slimframework.com/docs/features/templates.html $container['view'] = function ($container) { $settings = $container->get('settings'); $loader = new Twig_Loader_Filesystem('templates'); $twig = new Twig_Environment($loader, array( 'cache' => 'cache', )); // Add twig extension. $twig->addExtension(new \Twig_Extensions_Extension_Array()); return $twig; }; With this setting, Twig always

Pagination with Twig and Eloquent-5.2

走远了吗. 提交于 2020-01-03 02:08:56
问题 After following this video tutorial on building a PHP Authentication System with Slim/Twig and Eloquent 5.2. I have finished the video tutorial and have a working system. But I am failing to add pagination to the all user list on the 25th episode of the tutorial. Everything seems to work fine. but when I press page 2,3,4,etc... I am still getting the page 1 data. Here is the code I have so far: routes/user/all.php $app->get('/users', $authenticated(), function() use ($app) { $users = $app-

How to get the POST request entity using Slim framework

风格不统一 提交于 2020-01-02 19:13:10
问题 I have sent JSON data using android java by setting it in the post entity like this: HttpPost httpPostRequest = new HttpPost(URLs.AddRecipe); StringEntity se = new StringEntity(jsonObject.toString()); httpPostRequest.setEntity(se); How can I receive this json data in the php , where I am using Slim framework ? I have tried this: $app->post('/recipe/insert/', 'authenticate', function() use ($app) { $response = array(); $json = $app->request()->post(); }); 回答1: JSON is not parsed into $_POST

How to include JS/CSS files into templates of Slim Framework?

社会主义新天地 提交于 2020-01-02 07:17:32
问题 I am developing a simple web app with Slim framework. I got stuck with a probably simple problem. I want to include static files (CSS and Javascript) into my template. My project folder structure is as follows: index.php //<=== where all the routing happens. /flot layout.css jquery.js .... /templates first_template.php My header of first_template.php contains: <link href="../flot/layout.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript" src="../flot

Multipart/form-data example in slim micro framework

筅森魡賤 提交于 2020-01-02 07:03:24
问题 I have been developing apis for android and ios app in slim framework. Recently i came across a problem where i need to upload videos or images using multipart/form-data. Can any one provide me an example of it in slim micro framework? 回答1: Here is my simple example: HTML Form <form enctype="multipart/form-data" action="/uploadPhoto" method="POST"> Select photo: <input name="photo" type="file" /> <input type="submit" value="Upload" /> </form> PHP: $app->post('/uploadPhoto', function () use (