slim

Eloquent save() method not working inside for loop

穿精又带淫゛_ 提交于 2019-12-24 08:22:05
问题 I have a table like given below and this table is going to be used for project images. id: primary key project_id: a column that has correlation with projects. order_num: represents image list order for specific project (eg. interior view of project, exterior view of construction project, a different aspect etc...) +---------+-------------+-----------+ | id | project_id | order_num | +---------+-------------+-----------+ | 1 | 15 | 0 | +---------+-------------+-----------+ | 2 | 15 | 0 | +---

Redirect to route with GET parameters

风格不统一 提交于 2019-12-24 06:08:29
问题 I'd like a route that parses and puts together an array of GET parameters to redirect to another route that expects GET parameters. I had hoped this would work, where I pass $search_params as part of the pathFor() method: // SEARCH VIEW $app->get('/search', function ($request, $response, $args) { $api = $this->APIRequest->get($request->getAttribute('path'),$request->getQueryParams()); $args['data'] = json_decode($api->getBody(), true); return $this->view->render($response, 'search.html.twig',

Running slim framework on existing apache web server

大城市里の小女人 提交于 2019-12-24 03:05:26
问题 I am new to slim framework. Currently on my existing webserver which is on centos 7 I have other php based application running. So currently my directory structure is like this. var/www/html phpapp1 phpapp2 apislim The folder for the apislim I created was for slim framework. Below are the exact steps I did was 1. composer create-project slim/slim-skeleton 2. I rename the slim-skeleton folder to apislim 3. I make sure the owner is apache chown -R apache:apache apislim 4. In the httpd.conf I

How to create MySQL transaction using SLIM framework

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:48:16
问题 I am using the Slim framework to create a RESTful API . How can I create a transaction to execute multiple SQL statements and/or to be able to rollback some of those statements? 回答1: SLIM doesn't come with MySQL attached, so basically you'd do it the normal way, with either PDO or MySQLi, so basically (assuming PDO) you're looking for: $db->beginTransaction(); where $db is the PDO connection object you're using to use MySQL, see the manual However nothing from the transaction is run until you

File Upload to Slim Framework using curl in php [duplicate]

混江龙づ霸主 提交于 2019-12-24 01:18:50
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Failing to upload file with curl in heroku php app After handling a file upload in php, I am trying to send that file using curl to my rest api which uses Slim Framework. However, $_FILES is always empty once it reaches the function in Slim. sender.php if(move_uploaded_file($_FILES['myFile']["tmp_name"], $UploadDirectory . $_FILES['myFile']["name"] )) { $ch = curl_init(); $data = array('name' => 'test', 'file'

Redirecting with error on Slim Framework

半世苍凉 提交于 2019-12-23 22:48:01
问题 I want to redirect to a page (error.php, or maybe 404/406.php, whatever the error is) depending on the info in a form in my website. I managed to log an error like this: if ($date > $curdate) { return $response ->withStatus(406) ->withHeader('Content-Type', 'text/html') ->write('You can\'t select dates in the future!'); } How can I do it so it sends you to a page with that error in particular instead of logging/requesting it in the network tab? Edit for further explanation : Right now I get

Slim Framework Method not allowed. Must be one of: POST (405)

依然范特西╮ 提交于 2019-12-23 21:25:20
问题 I have written REST api in slim framework. When i call authenticate API from browser it troughs 'Method not allowed. Must be one of: POST' . Below is my code, please correct me where i went wrong. Index.php <?php require 'vendor/autoload.php'; require 'Authenticate.php'; $app = new \Slim\App; $app->post('/api/authenticate', \Authenticate::class); $app->run(); .htaccess RewriteEngine On RewriteRule ^ index.php [QSA,L] URL http://localhost/project/api/authenticate 回答1: if you type the URL in

Android Retrofit - POST request doesn't work, but in Postman it works

天大地大妈咪最大 提交于 2019-12-23 16:40:32
问题 This is the error I'm getting: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ JSON response I'm getting from Postman: { "title": "test title", "body": "test body", "userId": 1, "id": 101 } This is how I echoed the response from the rest API (used slim2 framework): $app->post('/posts', function() use($app){ $res = array( "title" => $app->request->post('title'), "body" => $app->request->post('body'), "userId"

Nginx configuration with Slim Framework, How to keep the .php url

穿精又带淫゛_ 提交于 2019-12-23 02:54:20
问题 My server has just wiped out by the provider, and I don't have the backup of the Nginx configuration file. It was completely lucky I got it working, now I don't know what to do. So I am having multiple files to do some specific things, and I am using Slim Framework on each file. The idea is to keep the php extension on the URL. Something like this: www.example.com/service.php/customer/1 www.example.com/api.php/data www.example.com/test.php/other-data/5 Does anyone have some clue on this? I

How to trigger Eloquent Manager in Slim 3.1 Dependency Injection

我的梦境 提交于 2019-12-22 14:54:08
问题 I have write my code to instantiate Eloquent Capsule/Manager using slim DI like this $container['db'] = function ($c) { $settings = $c->get('database'); $db = new \Illuminate\Database\Capsule\Manager; $db->addConnection($settings); $db->setAsGlobal(); $db->bootEloquent(); return $db; } And I have my route like this $app->get('/adduser', function() { $user = new Users; $user->name = "Users 1"; $user->email = "user1@test.com"; $user->password = "My Passwd"; $user->save(); echo "Hello, $user-