Comments (10)
I did not try it with Wordpress installed in a subfolder. I think you need to go in settings /wp-admin/options-general.php?page=slim_framework
and add site/wp/slim/api
for Base Path. And after your REST calls will look like /site/wp/slim/api/books/1
You can put that action like any other action in Wordpress, functions.php, plugin.php, etc... also is good to have it called before any content is sent to the browser.
from wp-slim-framework.
Thanks for the quick response!
I changed the setting but I'm still not seeing my added route response. I just get the wordpress "It looks like nothing was found at this location. Maybe try a search?" page.
The way I had slim working outside of wordpress was by requesting the page I was on and it would catch the routes like so: site/rest.php/put
Inside wordpress I am defining the routes in a class I have as a member of my plugin class that I instantiate by passing the $slim object after a callback in my plugin class is fired from the action 'slim_mapiing'. Am I doing that part correctly at least?
from wp-slim-framework.
Is your wordpress using permalinks ?
from wp-slim-framework.
Yes and I changed from the default to date and name.
from wp-slim-framework.
in your plugin.php you should have something like this.
/*
Plugin Name: Your plugin name
Version: 1.0.1
*/
add_action('slim_mapping',function(Slim\Slim $app){
//here you have access to slim $app and can define routes
$app->get('/site/wp/slim/api/books/:id',function($bookId)use($app){
//do something with this book
});
});
if like this still does not work i will try it by myself in a wordpress installed in a subfolder.
from wp-slim-framework.
I added that line to my plugin and requesting /site/wp/slim/api/books/1 returns a 404. The 404 looks like one that slim spits out, so that's hopeful. I just don't think the routes are working.
Thanks again!
from wp-slim-framework.
If you see a slim 404 then it's a good sign. I will try on my side with a wordpress in a sub folder.
from wp-slim-framework.
Alright after some tests today, for it to work with a Wordpress installed in a sub folder you will need to use it like in this example.
My wordpress is installed in /wp/
folder.
In the settings /wp-admin/options-general.php?page=slim_framework
i added
/wp/slim/api/
and saved, and my permalinks saved to use http://localhost.com/wp/%postname%/
Then i run this tests:
/**
* Plugin Name: Test Wordpress Slim framework
*/
//example outside a class
add_action('slim_mapping',function($app){
//notice the path is without "wp"
$app->get('/slim/api/books',function(){
echo 'get your books';
});
});
class TestPlugin{
function __construct()
{
add_action('slim_mapping',array($this,'routes'));
}
function routes($app){
$self = $this;
//notice the path is without "wp"
$app->get('/slim/api/students',function()use($self){
$self->listStudents();
});
}
function listStudents(){
echo 'i just listed all students :)';
}
}
//initialize the plugin
new TestPlugin();
And everything worked as expected. Also the calls i did over ajax like :
//then here we use '/wp/' because we need to tell Apache where Wordpress is with our plugin.
jQuery.get('/wp/slim/api/students')
jQuery.get('/wp/slim/api/books')
And it worked. I hope this was helpful :)
from wp-slim-framework.
That worked! Thanks!
To recap:
My issue had to do with the base url not being setup correctly. I had my wordpress installation within another site on localhost, therefore my path from the hostname (http://localhost/) needed to be corrected. In the Slim Framework settings I changed it from "/wp/slim/api/" to "/mt/wp/slim/api" where my site name on localhost was "mt".
Furthermore, the routes needed the proper base url plugged into them from the sitename, (http://localhost/mt/), of "/wp/slim/api".
Finally, when requesting the routes we need to use the right path from where we are to /slim/api. If we are within wordpress this request, I assume, will be "/slim/api" but if we are calling it from outside the wordpress environment it will be "/wp/slim/api".
If I end up making changes to your source to make this setup easier than I will send you a pull request. Thank you so much for your help and I look forward to using your code! 👍
from wp-slim-framework.
No problem, glad it worked for you.
from wp-slim-framework.
Related Issues (9)
- How can I use middleware for authentication? HOT 1
- CORS Headers and Content-Type settings HOT 3
- DI Container Clash HOT 5
- I'm getting the 404 but can't get an output HOT 3
- Using post data HOT 8
- Ajax CORS HOT 1
- Slim Framework 3 HOT 2
- Using composer to install plugin HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-slim-framework.