slim

Slim 3 console execution for cron

可紊 提交于 2019-12-08 07:07:15
问题 I'm trying to create some kind of import to move database info and transform data. In the future this import needs to be executed by cron every day. I want to use part of my written code and reuse some models and controllers. To do this I'm trying to call Slim 3 through the command line, but I have some problems. console command: php cli.php import I don't know how to process argv correctly. cli.php: require __DIR__ . '/vendor/autoload.php'; if (PHP_SAPI == 'cli') { $argv = $GLOBALS['argv'];

Error 404 with slim framework

半世苍凉 提交于 2019-12-08 06:45:19
问题 I am learning to code in PHP and mysql and need to be able to run PHP files using a wampserver. I have correctly installed wamp and have it online through Windows 8, however when I go to run my PHP file I am always given Error 404. I have ensured that my Slim file and .php file are in the correct directory and I have also modified the .htaccess accordingly so that it reroutes to the proper file if a URL is not found since I am testing this on my local machine. Here is a some of my sample code

Authentication Based REST API with Slim

那年仲夏 提交于 2019-12-08 06:22:56
问题 I'm not sure how to go with authentication method I have a way but don't know if it is secure or not. let me explain what I'm doing with REST API. I have a multiple users based web app, where users can login with their user name and password and do the stuff. I need to develop a mobile app for that web app. I'm thinking REST with Slim Framework, However I have no problem with Slim REST development but the authentication part is what I am not sure how to develop. However I have some idea Use

How to unit test Slim framework applications

北城余情 提交于 2019-12-08 02:20:25
问题 I've been trying to unit test modifying examples of other peoples code and each time I get to the point my tests are running without errors - I just get the same failures when I expect them to pass. There isn't a great deal of documentation online, and I don't really know where else to go with this. Can anyone see where in my code I'm going wrong: bootstrap.php (phpunit bootstrap file) This is basically just a container for the $app object. I initiate the $app object with the same files I

Routing issue with Slim framework

僤鯓⒐⒋嵵緔 提交于 2019-12-08 01:59:27
I just got started with Slim. My application for the moment is something like this: <?php require 'vendor/autoload.php'; $app = new \Slim\Slim([ 'debug' => true ]); var_dump($app->request()); $app->get('/:name', function ($name) { echo "Hello, $name"; }); $app->get('/', function () { echo 'hello world'; }); $app->run(); I am running it on localhost using PHP built in web server. For every request I try in the browser (or Postman, or CURL), what I get is always "hello world", as if the first route is not considered. Moreover, if I remove the second route, I always get a 404. Am I forgetting

How can I composer update on OpenShift?

筅森魡賤 提交于 2019-12-07 14:58:40
问题 I am trying to use Slim on OpenShift with a free node. I can run composer update from the SSH sessions without any problem. The only problem is every time I want to commit files through git I have to go to the console and run composer install again. My question is there is any easy way to workaround this? I tried a BASH script in /project/.openshift/action_hooks/post_deploy but the server is not creating the vendor folder under runtime/repo 回答1: I always do it via action hooks: Inside my

Front controller pattern - is router a front controller?

人盡茶涼 提交于 2019-12-07 10:54:19
问题 I'm trying to understand how a Front Controller should look like. From Wikipedia, The Front Controller pattern is a software design pattern listed in several pattern catalogs. The pattern relates to the design of web applications. It "provides a centralized entry point for handling requests." So, is the code below that handles routes in Slim a front controller? $app = new \Slim\Slim(); $app->get('/books/:id', function ($id) use ($app) { // Get all books or one book. $bookModel = new ...

Eloquent fatal error: argument passed not the right instance

孤街醉人 提交于 2019-12-07 07:16:17
问题 I'm in the process of building an endpoint system in PHP using Slim and Eloquent, as outlined here. When running it in my local dev, the code below fails with what appears to be a Fatal Error based on what the methods are expecting // Load Eloquent $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(); $conn = $connFactory->make($settings); $resolver = new \Illuminate\Database\ConnectionResolver(); $resolver->addConnection('default', $conn); $resolver->setDefaultConnection(

Reading token with slimframework

蓝咒 提交于 2019-12-07 04:51:35
问题 I'm using SlimFramework and JWT to handle token based authentication with login and password. I managed to login and send token in response. Here is my code: <?php require_once("vendor/autoload.php"); $app = new \Slim\Slim(); $app->add(new \Slim\Middleware\ContentTypes()); $app->post('/auth/login', function () use ($app) { $params = $app->request()->getBody(); if ($params['email'] == "login" && $params['password'] == "password") { $key = "example_key"; $token = array( "id" => "1", "exp" =>

Not getting expected response from Guzzle

非 Y 不嫁゛ 提交于 2019-12-06 17:12:38
问题 I'm trying to build an endpoint that forwards the data passed to it to an API using the Slim PHP Framework and I'm having trouble getting my response from a Guzzle request. $app->map( '/api_call/:method', function( $method ) use( $app ){ $client = new GuzzleHttp\Client([ 'base_url' => $app->config( 'api_base_url' ), 'defaults' => [ 'query' => [ 'access_token' => 'foo' ], ] ]); $request = $client->createRequest( $app->request->getMethod(), $method, [ 'query' => $app->request->params() ]); var