slim

PHP Slim RESTful API - Two Table Join Nested JSON

给你一囗甜甜゛ 提交于 2019-12-13 04:27:47
问题 I currently am working on a RESTful API with the PHP Slim Framework. I currently encountered the following problem: I have to tables with an 1:n cardinality. With an GET-Call I want to get the data of the main table and nested in there all of the tables with the foreign key. Like this: Planed Result [{ "id":"1", "ueberschrift":"UEBER", "text_kurz":"Lorem ipsum...", "kategorie":"HEAL", "bilder":[ {"src":"wed1.png"}, {"src":"wed2.png"} ]},...... This is how a part of my mysql database looks

OAuth 2.0 Example Auth Server

孤街醉人 提交于 2019-12-13 04:26:49
问题 I want to try with this OAuth2-Server Example ( https://github.com/alexbilbie/oauth2-example-auth-server ) but when I want to run it gives me error " Fatal error: Interface 'OAuth2\Storage\ClientInterface' not found in /var/www/oauth2-auth-server/model_client.php on line 2 " I think I need to add autoloader to composer.json I did it but forever it gives me this error. But I also think in oauth.php I found this line: // Initiate the auth server with the models $server = new \OAuth2\AuthServer

OPTIONS Preflight causing POST request to hang

可紊 提交于 2019-12-13 04:09:11
问题 I've been having issues with the CORS OPTIONS preflight request with my angular application. To be brief I'm trying to implement a simple login which sends a POST request to my server, which has a backend built using PHP\Slim, carrying the user's credentials. The CORS OPTIONS requests first and I handle it with slim to respond with a 200 OK, so when the browser gets the OK it finally sends my POST with the credentials, but then it just hangs...no response code, nothing. Honestly, this is

fetch data from table using REST API

♀尐吖头ヾ 提交于 2019-12-13 03:51:39
问题 I am designing REST api using Slim framework. I am using database mySql. and i am designing this API in php. I am trying to fetch data about student from my table. I am trying like this:- <?php header('Content-type: application/json'); // Include the Slim library require 'Slim/Slim.php'; // Instantiate the Slim class $app = new Slim(); // Create a GET-based route $app->get('/hello/:name', 'hello'); function hello($name) { // here is code to access detail of $name echo $name // how can i get

Slim 3 method getUploadedFiles() returns an empty array

不想你离开。 提交于 2019-12-13 03:37:20
问题 When trying to mock a test with a test file I get stuck. Basically the withUploadedFiles() method wants me to work with an array. As you can see down below, I try to var_dump to see if it has worked but in every case the array is empty. I wonder why this is? If I only var_dump my array with the name $uploadedFiles it shows me the content. Do you see where my mistake is? <?php use Slim\Http\UploadedFile; class FileControllerTest extends PHPUnit_Framework_TestCase { // ... public function

Slim Framework and Twig templating engine

纵然是瞬间 提交于 2019-12-13 02:13:08
问题 Hello so I have a simple code here that will render home.html using slim framework and twig. Here's the codes: In my index.php file: require_once 'vendor/autoload.php'; $app = new \Slim\Slim([ 'debug' => true, 'templates.path' => 'app/views' ]); $app->view = new \Slim\Views\Twig(); $app->view->setTemplatesDirectory("app/views"); $view = $app->view(); $view->parserOptions = ['debug' => true]; $view->parserExtensions = [new \Slim\Views\TwigExtension()]; $app->get('/home', function () use ($app)

How to remove index.php from url slim framework setting VirtualHost?

天涯浪子 提交于 2019-12-13 01:19:15
问题 reference image: In this route I have the example: C:\wamp\www\api I work with centos in VirtualBox. In the console of centos I can get into the same folder with this route: cd /var/www/html/sistemaTareas/api Well, in API folder I have: index.php | .htaccess | Slim Index.php: <?php require 'Slim/Slim.php'; \Slim\Slim::registerAutoLoader(); $application = new \Slim\Slim(); $application->get('/hello/:firstname/:lastname', function ($firstname,$lastname) { echo "hola, $firstname $lastname"; });

Pass arguments in Slim DI service

試著忘記壹切 提交于 2019-12-12 18:35:48
问题 I have a service that I want to access from a route but pass arguments to. $container = new \Slim\Container(); $container['myService'] = function($arg1, $arg2) { //my code here }; $app = new \Slim\App($container); and inside my route, I try to call the service like so: $this->myService('my arg1', 'my arg2'); This is not working. When I try to call it without specifying the arguments, it works. How to call with arguments? Or is that an alternative way to specify a function or method to be

Array after array_unique function is returned as an object in JSON response

不羁的心 提交于 2019-12-12 07:48:36
问题 im trying to merge two arrays with omitting duplicated values and return it as a JSON with Slim framework. I do following code, but in result I get unique property of a JSON as object - not as an array. I don't know why does it happen, and I'd like to avoid it. How can I do it? My code: $galleries = array_map(function($element){return $element->path;}, $galleries); $folders = array_filter(glob('../galleries/*'), 'is_dir'); function transformElems($elem){ return substr($elem,3); } $folders =

Parse error when run illuminate/database/capsule with bootEloquent() in PHP

左心房为你撑大大i 提交于 2019-12-12 06:52:45
问题 I'm trying to make a mysql connection within a php environment using Slim and the package illuminate/database . Following the documentation I have created a new $capsule instance, I have passed the array with connection data through the addConnection method and then I have run bootEloquent() method: <?php use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule->addConnection([ 'driver' => $app->config->get('db.driver'), 'host' => $app->config->get('db.host'),