FAQ Database Discussion Community


PHP Header exists but cannot retrieve

php,json,apache,slim
I am using this method to make apache header request work in nginx. if (!function_exists('apache_request_headers')) { function apache_request_headers() { foreach($_SERVER as $key=>$value) { if (substr($key,0,5)=="HTTP_") { $key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5))))); $out[$key]=$value; }else{ $out[$key]=$value; } } return $out; } } I retrieve the header like so $headers = apache_request_headers(); and use an...

Error Packaging into a Phar file an entire Slim Application

php,slim,phar
I have a Slim Application with the following directory structure: app/ vendor/ www/ config.php In app/ I have the relevant files of the project, in vendor/ the dependencies managed by composer and in www/ the files accesible by the web server. So I am thinking to create a Phar file...

Specifing parameters in REST API GET request

php,android,api,http,slim
I want to have the ability to specify the image size of a product in ONE request, I have different ideas about this, here they are: mysuperstore.com/api/categories/40/products/53?width=100&height=100 I think this is bad practice, because it is unclear what does width and height mean, maybe there is physical size of product....

Caching issue in angularJS application

angularjs,caching,orm,eloquent,slim
I've an admin panel which is a pure angularJS application, which uses REST api for data manipulation. REST api is built using SlimAPI framework and Laravel's Eloquent ORM. I'm facing caching issue in admin panel. Even though if a add new content to the system, it'll not show up in...

Slim PHP custom http response pages

php,httpresponse,http-status-code-403,slim
Ok I have read the docs on Slim PHP and read quite a few tutorials, and have an application nicely under way. However I am trying to get to grips with things such as customizing the HTTP response codes. I have managed to get the following : $app->notfound('template.file', array( 'data'...

How to respond in Middleware Slim PHP Framework

php,rest,authentication,middleware,slim
I am creating middleware for auth into REST API. My API is created using Slim PHP Framework ,which in case provide great features to build APIs. One of this feature is Middleware. I need to check credentials in Middleware and respond with an error (HTTP code with JSON descriptions) to...

Connecting an iOS app to a database using Swift, SlimPHP and MySQL

php,mysql,database,swift,slim
I have a website setup, where users can register, and that data is stored into a database. My website is built using SlimPHP along with some other dependencies, such as twig. Is there a dependancy that I can use to help connect my iOS app to my database so users...

SlimPHP: How to pass array of flash messages to twig template

php,twig,slim
I would like to send an array of flash messages to a twig template. The code would go like this: $errors = $validation->errors(); $app->flash('error', $errors); $app->response->redirect($app->urlFor('register'), 303); This is what I've tried in the twig template, but it doesn't render the messages: {% for error in flash.error %} {{ error...

API Authentication using HMAC

authentication,hash,oauth-2.0,slim,hmac
I am looking for a decent method of authentication to use when writing a simple API for use within our internal systems. Other questions on Stack Overflow have suggested HMAC along with links to tutorials, which I went ahead and decided to implement. After setting this up, I realized I...

How do you get the current url in Twig?

twig,slim
Inside a twig template I will check if url is: http://example.com/search?keyword=test {% set pageTitle = query %} query is test else {% set pageTitle = different %} How I can do? Thank you....

PHP Slim API 404 not found

php,.htaccess,slim
I'm trying to create an API using php and php slim. my folder structure: API: app -> app.js libs -> Slim v1 -> .htaccess and index.php htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L] index.php require '.././libs/Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app = \Slim\Slim::getInstance(); $app->get('/orderoverview/:customerID', function ($customerID)...

htaccess config for slim php framework

php,regex,.htaccess,slim
I use Slim php framework to build some action inside index.php page: so this is the way I call my action: index.php/action1 $app->get('/action1',function () use ($app){ echo "this is action 1"; }); index.php/action2 $app->get('/action2',function () use ($app){ echo "this is action 2"; }); Now I want my url become pretty...

Why is my HTML so poorly formatted when rendered with Smarty?

php,wamp,smarty,slim,smarty3
Why is my HTML so poorly formatted when viewing the source code? Working with: WAMPSERVER (64 BITS & PHP 5.5) 2.5 Slim Framework v2 RedBeanPHP 4.2 Smarty 3.1.21 index.php: <?php // load required files require 'class/Slim/Slim.php'; require 'class/RedBean/rb.php'; // register slim auto-loader \Slim\Slim::registerAutoloader(); // set up database connection R::setup('mysql:host=localhost;dbname=slimcms','root',''); R::freeze(true);...

Send a .jpg image to Wb Service from an Android Device

php,android,rest,slim
I need to send jpg images from my android app to my web service and store it in my database. I'm using android studio and my web service is Php Rest with a slim framework. I reallly have no idea what to do.

Not getting JSON data when using AJAX, Slim and PHP

php,api,slim
I am learning to create Rest API using Slim, but got stuck in here. I tried many things mentioned on internet but its still not getting value. My Ajax: $.ajax({ type: 'POST', url: 'pages/search', dataType: "json", data: {'val1':value1,'val2':value2}, success: function(data){ alert(data.val1); } }); My PHP using Slim: <?php require 'Slim/Slim.php';...

How can I introduce Slim framework in XAMPP?

xampp,slim
I want to introduce Slim framework into my XAMPP but I don't know where I have to allocate the folder. I was searching through the folders of xampp folder but I didn't see any of them that could be the right way. Any help would be appreciated. Thanks in advance!...

GET request to an API REST always return the index.php file

php,.htaccess,rest,slim
I'm developing a REST api with Slim. When I use my api in localhost everything works well, but when I try to use it on my server it doesn't work well, returning the content of the index.php. For this question I'll use the example app of Slim framework. So my...

twig error when using in slim

twig,slim
Hi I need interate twig to Slim application, I install twig with composer and im my script I have <?php use Slim\Slim; use Slim\Views\Twig; use Noodlehaus\Config; use Codecourse\User\User; session_cache_limiter(false); session_start(); ini_set('display_errors','On'); define('INC_ROOT', dirname(__DIR__)); require INC_ROOT.'/vendor/autoload.php'; $app = new Slim([ 'mode' => file_get_contents(INC_ROOT.'/mode.php'), 'view' => new Twig(), 'template.path' => INC_ROOT ....

php web service encoding doesn't work with accent

php,json,slim
I've made a little web service in php with slim framework it works unless one of the json fields of the json object returned contains a character like á,é,í,ó,ú ,the enconding of the database is ut8_spanish_ci and this is the web service code <?php header('Content-Type: application/json; charset=utf-8'); header("Access-Control-Allow-Origin: *"); require...

Slim PHP 500 Internal Server Error

php,.htaccess,slim
I'm currently attempting to set up a Slim project with the following directory tree: public_html |-- Mini |-- public |-- vendor |-- index.php (Slim) |-- .htaccess The document root is public_html, and the contents of the .htaccess are as follows: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^...

Slim PHP Framework middleware custom URL filter

php,rest,authentication,middleware,slim
I am creating API using Slim Framework. I need to filter requests required authentication and route them to the specific auth handler. Or it would be better to say that I need to filter URI that don't require auth (public information). I have created following middleware skileton class TokenAuth extends...

Slim Framework with ORM (Eloquent) connect multiple db

orm,eloquent,slim,multiple-databases
I am using Slim Framework with Eloquent 4.1.x as ORM for a project and need to connect to multiple databases. I followed this link to setup the ORM. But how can I connect to multiple databases by following the given tutorial? In my models I have different files that are...

PHP Slim: multiple functions in one file cause errors

php,slim
I am fairly new to PHP slim but it's working great for me actually. But I have a problem that I think is really strange! I have a PHP file with all my API functions to get or edit data in my database. Each of these functions works great seperatly...

How twig support variable with space in url?

twig,slim
I have this code: {% if currentUrl() == siteUrl('/tag/' ~ tag) %} {% set pageTitle = tag %} {% endif %} when url is http://example.com/tag/test page title is: test but when url is http://example.com/tag/test test1 page title is: empty How I can fix issue? Thank you....

Form Creation and Validation in Slim Framework

api,slim
I gonna develop a form using slim framework. I know we can develop REST API's using SLIM. I need to know whether we can design forms and validate those. Thanks in advance....

Slim framework - 500 Internal Server Error

php,apache,.htaccess,mod-rewrite,slim
There is probably a very simple solution to this but I can't seem to figure it out. I'm working a Slim Project which was working fine. I just did a fresh install of Yosemite on my system. I have installed MySQL and enabled PHP (5.5.20). I moved my Slim project...

I use Slim Framework. Why server response time is very big?

php,slim
I use this code, and server response in ~500-700ms. If write 'return;' after create Slim object as $app, response time is ~200-250ms. Why this framework work very slow? Can i do it fast? require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(array( 'debug' => true, 'templates.path' => './templates' )); $headerType = $app->request->headers->get('Accept');...

Pass 'use' objects to Routes with Slim Framework

php,pdo,frameworks,routes,slim
I have just began using Slim Framework for a very basic REST API project and it is absolutely perfect for my needs. I am however trying to determine how to use both route groups in combination with passing objects to the routes through 'use'. How can I pass the $app...

Slim - Swift Mailer on the route is work but if after moved on controller get errors

php,swiftmailer,slim,mailer,slimframework
I add libraries slimcontroller and swift mailer in my slim project, when in route goes well: Route::get('/send', function() use ($app, $mailer) { $message = Swift_Message::newInstance('Activation Code') ->setFrom(array('[email protected]' => 'xxx')) ->setTo(array('[email protected]' => 'xxxs')) ->setBody('Test'); // Send the message $results = $mailer->send($message); // Print the results, 1 = message sent! print($results); });...

Should I implement user data sanitization/validation as middleware?

php,validation,middleware,slim,sanitization
I'm reimplementing my user management system with Slim, and I'm trying to figure out where I should do user data sanitization/validation. I've been reading about middleware, and I'm wondering if this is an appropriate way to implement data validation. My plan for validation is to use a validation schema (a...

Captured variable from Slim route is undefined

php,variables,slim
I have the following slim route, but for some reason the $cid variable is not being recognized. The $cid var should be initialized from the first line of the code below where it says :cid and then it is used in the path variable of the response array further down....

Can't send file as form data using cURL

php,curl,slim
I am trying to send a cURL request via the command line. Below is my request curl -i http://localhost/test/index.php -X POST -F "name=file.png" -F "[email protected]/var/www/html/test/file.png" The problem I'm having is that the file isn't getting sent with the request. The name is getting sent fine but not the file. Can...

Slim Framework and .htaccess

apache,.htaccess,slim,slimframework
I don't know what I am doing wrong but if I add a .htaccess protection to my directory with the following content my SLIM application won't work: AuthType Basic AuthName "no entry" AuthUserFile /www/html/management/.htpasswd Require valid-user without this .htaccess file it works :(. The directory tree looks as follows html/...

why there is no $app->request->delete() in slim framework?

rest,slim
I develop API with slim framework. I know there is no request parameter for delete like her friends (put, get, post). $token = $app->request->get('token'); $token = $app->request->post('token'); $token = $app->request->put('token'); When i take parameter in delete, i always use get to take the parameter....

Create an XML template for app response

php,xml,slim,slimframework
So here is my code... $app->post( '/chk_db', function () use ($app){ require_once 'lib/mysql.php'; $dx = connect_db('MyPhotos'); //XML RESPONSE $app->response->setStatus(0); $res = $app->response(); $res['Content-Type'] = 'application/xml'; $view = $app->view(); $view->setTemplatesDirectory('./'); $oArray = array("Status"=> $dx.status, "code" => $dx.code); return $app->render('chkdb.xml', $oArray); } ); I wanna know how to create the chkdb.xml template...

POST variables in PHP Slim rest api

php,slim
I'm trying to get a POST variable, does Slim have a special way of retrieve parameters ? sending parameter in http body. For example, if I wanted to use the following: http://localhost:5057/PB/App/ And BnkId=910155&Acc=0020150010561 are parameters ...

Optional parameters on index route

php,slim
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...

Set Custom Views for Slim after it's been instantiated

php,slim
I'm working on a very old legacy website(think PHP 4 constructs). Slowly but surely I'm refactoring most of the code. Since it's not really a huge amount of code I decided to use Slim. I'm using Custom Views, and probably in the near future I'll go for a tempting engine,...

Slim framework - php - how prevent injections?

php,android,security,sql-injection,slim
As an android developer I would like prepare my server for request from android app. First aim was to create request link for adding items into database. So I have created something like that below in php file by Slim framwork. My question is: is there any chance to inject...

Post Routes Slim PHP

php,post,forum,slim
I am trying to create a forum for my website. I have been running into issues with posting data. I planned for it to be so that when the user clicks on a category, it POSTs the category's id so I can then get that id and then list all...

How To Pass A Twig Output String Into the urlFor() Function

php,twig,block,slim
I would like to pass the id of a category into a parameter using urlFor(). {% for category in categories %} <br> <p><a href="{{urlFor('showTopic.post', {"cat_id": "{{category.id}}"})}}">{{category.category_title}}<a><br>{{category.category_description}}</p> <br> <br> {% endfor %} This currently does not work. It just passes in {{category.id}} instead of the actual id for the category. I...

Slim Post Request, No Response Data

php,slim
I have the following code $app->post('/return/', function() use($app){ error_log($app->request()->params('data')); $res = $app->response; $res->setStatus(400); $res->write('You made a bad request'); $res->headers->set('Content-Type', 'text/plain'); }); The http request will succeed with status code 200, but i will get no response data and wondering if my SLIM code is working properly? I have no problems...

SLIM Application error. Code 8: Array to string conversion

php,mysql,pdo,mysqli,slim
I'm currently working in a mobile application (Front-end) which brings some data through a Php Slim backend from a MySQL database using PDO. This (Back-end) was developed by a team mate and works like a charm on his computer. There's a GET route which is supposed to return some JSON...

Conditionally add class to link_to with slim syntax

ruby-on-rails,ruby,slim
I have a link and the code is as follows: = link_to 'Payment', account_payment_path, class:{'active'} and I want to add a conditional logic to the view, so if the action_name is same, then add class active I then change to the following code = link_to 'Payment', account_payment_path, class:{'active' if action_name...

Stylesheet not found when link is correct

php,html,css,.htaccess,slim
I am trying to link my stylesheet to my php template for my website. I used the link: <link rel="stylesheet" type="text/css" href="{{app.request.basepath }}/App/views/templates/style.css"> Now, this works on my localhost server(I use MAMP), but when i upload the files to the web host I get the error: Failed to load resource:...

always_populate_raw_post_data - Trouble accessing request payload from Backbone create

php,backbone.js,xmlhttprequest,slim,postdata
I am trying to save a collection to my database RESTfully using Backbone.js with the SLIM php framework running on my server. Here is my collection: var newUser = this.collection.create( formData, { wait: true, success: $.proxy(function() { this.collection.currentUser = newUser; App.Router.navigate('', { trigger: true }); }, this) } ); Here...

Slim framework INSERT query not working

php,mysql,insert,slim
I'm using the Slim framework to build a RESTful API for a server database. I have been racking my mind trying to figure out why my INSERT statement below is not executing. Every time I run it, I get a response saying "error: true" and the "Failed to save sound....

How to add angular attribute directive to input in rails slim template?

angularjs,html5,templates,ruby-on-rails-4,slim
Trying to attach custom angular attribute directive to rails slim template. But all attempts are not successful. Here is the code input#title.form-control placeholder="Product titile" type="text" ng-model='product.title' server-error where 'server-error' is a custom directive. But when browser renders this html this directive is cutted off and printed as a plain text....

Slim framework and GET/PUT/POST methods

api,methods,httprequest,slim
For example, i use this code for testing routes: $app->get('/api', function () { echo 'get!'; }); $app->post('/api', function () { echo 'post!'; }); $app->put('/api', function () { echo 'put!'; }); For api testing i use RestClient plugin for Chrome. When i try do GET request, response is 'get!'. Its good....

call to undefined function apache_request_headers Slim framework

php,apache,http,slim
I'm only posting this because none of the other posts have helped solve my problem. I'm using slim and advanced rest api app on chrome for testing. I've tried many suggestions on the web but nothing is working. I'm running php 5.5 on hostgator. I am getting the error when...