Comments (5)
$_GET
is used to retrieve parameters passed by the URL query string.
http://php.net/manual/it/reserved.variables.get.php
For instance, if you call your script with this request:
http://example.com/foo?username=bar
the $_GET['username']
variable is assigned to bar
.
By the way, in your script you are redeclaring the GET /
route 2 times, and you are not invoking the route dispatcher µ::_();
after the route definitions.
from mu.
@lastguest , added µ::_();
Please tell me how to get the user name using $ _GET using your PHP micro-router?
from mu.
write a simple example of the method $_GET
from mu.
Just try this :
µ::GET('/', function(){
var_dump( $_GET );
});
µ::_();
Now you can call it in your browser like this :
http://localhost:8080/?name=hello+world&number=123
array(2) { ["name"]=> string(11) "hello world" ["number"]=> string(3) "123" }
Important:
• You must setup a front-controller pattern for redirecting all requests to the index.php
file.
If you are using Apache you must define an .htaccess
like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
• Some web server configurations appends the query string part of the request URL to the $_SERVER['REQUEST_URI']
global, therefore breaking routing on parameters passing.
In these cases you must replace the REQUEST_URI
text in µ
class definition with REDIRECT_URL
.
A more stable approach is replacing the getenv(REQUEST_URI)
with strtok(getenv(REQUEST_URI),'?')
in µ
class definition.
Please, remember that this is an experiment just for fun. Do not use it in production!
from mu.
@lastguest , well, thank you
from mu.
Related Issues (4)
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 mu.