slim

how to Mod-rewrite php + Slim url to sub-directory

人盡茶涼 提交于 2019-12-01 11:43:07
问题 I am using Slim 2.4 and php 5.3. My Directory Structure in localhost is something like this : Web Root AppName API v1 include Slim <- Slim Framework tools .htaccess (#1) index.php (#1) Assets css js img .htaccess (#2) index.php (#2) I wan to access localhost/AppName/v1 that will open up localhost/AppName/API/v1 . This is working partially as further parameters are getting ignored. When I am trying to get localhost/AppName/v1/anyOtherVariable it opens up localhost/AppName/API/v1 only. Now, #1

Dependency Injection Slim Framework 3

非 Y 不嫁゛ 提交于 2019-12-01 04:34:07
I'm using Slim Framework 3 to create an API. The app structure is: MVCP (Model, View, Controller, Providers). Is it possible to have Slim Dependency Inject all my classes? I'm using composer to autoload all my dependencies. My directory structure looks like this: /app - controllers/ - Models/ - services/ index.php /vendor composer.json Here's my composer.json file. { "require": { "slim/slim": "^3.3", "monolog/monolog": "^1.19" }, "autoload" : { "psr-4" : { "Controllers\\" : "app/controllers/", "Services\\" : "app/services/", "Models\\" : "app/models/" } } } Here's my index.php file. Again, the

Dependency Injection Slim Framework 3

孤人 提交于 2019-12-01 01:12:33
问题 I'm using Slim Framework 3 to create an API. The app structure is: MVCP (Model, View, Controller, Providers). Is it possible to have Slim Dependency Inject all my classes? I'm using composer to autoload all my dependencies. My directory structure looks like this: /app - controllers/ - Models/ - services/ index.php /vendor composer.json Here's my composer.json file. { "require": { "slim/slim": "^3.3", "monolog/monolog": "^1.19" }, "autoload" : { "psr-4" : { "Controllers\\" : "app/controllers/"

Routing with AngularJS and Slim PHP

一世执手 提交于 2019-12-01 00:28:16
I have been working with AngularJS and I am trying to connect my application to it. So far I have used Slim PHP and can get all records from my MySql database but I am not able to get a specific record. I have written the PHP code and can navigate to "../requests/#" and get a JSON response of the correct ID record. What I cant get is it to work with the interface. With the code below I can create a list of requests and click on the one I want to open viewRequest.html. However my view request page ALWAYS brings up the first record and not the record in the URL. Slim - Index.PHP <?php require

Slim 3 get current route in middleware

五迷三道 提交于 2019-11-30 18:42:23
I want to get the name of the current I route in a middleware class. Previously (in Slim 2.*) you could fetch the current route like so: $route = $this->app->router->getCurrentRoute(); But this function has been removed in the 3.0 version of Slim. I've found the following code in the __invoke method of Slim\App : // Get the route info $routeInfo = $request->getAttribute('routeInfo'); /** @var \Slim\Interfaces\RouterInterface $router */ $router = $this->container->get('router'); // If router hasn't been dispatched or the URI changed then dispatch if (null === $routeInfo || ($routeInfo['request'

Passing Session to TWIG template

无人久伴 提交于 2019-11-30 15:48:30
i have a problem when i want to get $_SESSION['session']; in twig template using slim micro Framework. this is my code : <!DOCTYPE html> <html> <head> <title>{{ title }} </title> </head> <body> <p> welcome <?php echo $_SESSION['username']; ?> <p> {{ body }} </p> <a href="http://localhost/slim/public_html/logout">logout</a> </body> </html> i can't get session username with that code. any suggestion how to passing session to twig template? You should register session as a twig global, so it becomes accessible in your templates. //$twig is a \Twig_Environment instance $twig->addGlobal("session",

Slim 3 - how to get all get/ put/ post variables?

落爺英雄遲暮 提交于 2019-11-30 10:24:14
问题 How I can get all get/ put/ post variables like in Slim 2 for Slim 3? Slim 2, $allGetVars = $app->request->get(); $allPutVars = $app->request->put(); $allPostVars = $app->request->post(); How can I do that in Slim 3? And, for example, http://example.com/books/1?title=hello&content=world How can I get the params in title and content in Slim 3 now? Slim 2, $title = $app->request->get('title'); $content = $app->request->get('content'); How can I do that in Slim 3? 回答1: Get all get/put/post

Slim framework - cannot interpret routes with dot

笑着哭i 提交于 2019-11-30 09:07:15
问题 Problem Statement I'm currently working on an internal RESTful API, and I'm using our main domain name as an environment identifier. However, I noticed that Slim does not like it at all for a route to have dot in there. Sample case I have a local web server running using PHP's built-in webserver, and I invoked php -S 0.0.0.0:5000 to get it running. Once the web server is up, I have a simple 'hello world' on the index page. Everything's working fine and dandy. I then set up a route as

Backbone & Slim PHP - Access-Control-Allow-Headers - Can GET information, can't POST it?

时间秒杀一切 提交于 2019-11-30 05:28:51
I'm using Backbone and the Slim PHP framework. I'm trying to post information to my API, however Access-Control-Allow-Headers keeps causing me problems... My console reads: OPTIONS http://api.barholla.com/user/auth 405 (Method Not Allowed) zepto.min.js:2 XMLHttpRequest cannot load http://api.barholla.com/user/auth. Request header field Content-Type is not allowed by Access-Control-Allow-Headers. My headers read: Request URL:http://api.barholla.com/user/auth Request Method:OPTIONS Status Code:405 Method Not Allowed Request Headersview source Accept:*/* Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q

Slim 3 autoloader

两盒软妹~` 提交于 2019-11-30 04:56:40
问题 I'm new to slim framework, and can't figure out how to use the autoloader to autoload my classes. I created a app/models/myclass.php but of course when I try to use it I get a class not found. I'm not sure which is the right way to autoload classes, or the naming convensions I should use. Should I do it via the composer.json somehow? I'm searching the net for several hours without any solid answer on that. UPDATE : Managed to do it like that: added model in : app/src/Model/Client.php added