botnary / wp-slim-framework Goto Github PK
View Code? Open in Web Editor NEWSlim framework as Wordpress plugin
Slim framework as Wordpress plugin
I have the plugin installed in the correct spot, I've changed the settings for the plugin to nano/api/
, and I'm using /%postname%/
, for the permalinks. I'm running locally via MAMP. I created a test plugin to play with Slim:
add_action('slim_mapping',function(Slim\Slim $app){
//here you have access to slim $app and can define routes
$app->get('slim/api/books/:id',function($bookId)use($app){
echo 'book';
});
I'm getting the Slim 404 when I pass localhost/nano/api/books/12
. I'm hoping to get "book" back. The idea, once I get working is to return json. Right now I just want to return something with my get calls instead of getting the Slim 404 page (I know it's not the WP 404).
Hey,
Love your plugin, any chance it can be upgraded to Slim 3 ?
Thanks
Hi, I'm just getting set up with this plugin and I'm wondering how I pass Post data through and then use it from the slim_mapping
function.
I'm querying the api with javascript, (specifically Angular):
req = {
method: 'POST',
url: CONSTANTS.external.server + '/slim/api/posts',
headers: {
'Content-Type': 'application/json'
},
data: {
'abc': '123',
'def': '456'
}
}
$http(req).success(function(response, status) {
...
Then in the PHP file, the slim_mapping
function looks like:
public function slim_mapping($slim) {
$context = $this;
$slim->post('/slim/api/posts', function($data)use($context) {
$context->addPost($data);
});
}
private function addPost($data) {
echo json_encode($data);
}
How do I get hold of the passed data within the data
object?
I'm getting the following error message when trying to access my API, which I created using wp-slim-framework:
"XMLHttpRequest cannot load http://myafrigrid.com/slim/api/marker/12293-785. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8101' is therefore not allowed access."
How can I fix this?
I'm sort of a newbie.
I have installed the plugin on a wordpress instance as prescribed. I am using this Slim application in 2 plugins. When I create an object in the DI container in one plugin the container gets overwritten by the container created and used in the other plugin. I can make the index files of the 2 projects available on request. Wouldn't mind a simple example on how to use this slim plugin with 2 other plugins.
Could you advise?
Hi @Botnary . Do you plan to use Composer to install the plugin ? Perhaps this plugin can integrated with composer when the plugin using the Slim 3.
I'm trying to use this plugin to convert an app made with slim to a wordpress plugin.
However I need a way to protect access to routes and I was using a middleware to check if user is logged in.
So I have added this line:
require_once 'Slim/Middleware/HttpBasicAuth.php';
But I got this error:
Fatal error: Class 'Slim\Middleware' not found in E:\wamp\www\Blog\wp-content\plugins\wp-slim-framework\Slim\Middleware\HttpBasicAuth.php on line 6
It seems that my middleware cannot extends parent class:
namespace Slim\Middleware;
class HttpBasicAuth extends \Slim\Middleware
COuld you help me? I should try another approach? What is the better way to check if user is authenticated to prevent access to routes?
Thanks
Hello, I am looking to use Slim with wordpress and another custom plugin I am developing and I am using this plugin you developed here but I have a couple of questions:
Where does /slim/api actually exist that the api routes live on? If my wordpress site is at http://localhost/site/wp/ should I change the setting in the settings page for Slim Framework? Or do I try accessing it at http://localhost/site/wp/slim/api which I have tried but does not work.
Also, where are you putting the code that calls the action for slim mapping? I put my code in my custom plugin and I just want to make sure it is being called with the correct timing.
Thank you in advance for your assistance!
Can we set the HTTP headers through this library? I'm having a fuss getting CORS requests working or content type set to json for the response. Hoping this can accomodate.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.