Comments (12)
Hello,
Could you please put your codes (middleware, directory structure, etc.) here?
There some tests for the middleware https://github.com/miladrahimi/phprouter/blob/master/tests/MiddlewareTest.php and it shows that the router supports middleware classes everywhere.
from phprouter.
So following your examples i created a simple redirect with no checking now if i simply include the file
get('/auth', function () { return 'OK'; }); $router->get('/', function () { return 'This is homepage!
'; }); $router->get('/users', 'Users@index',App\Middleware\Auth::class); $router->post('/users/Store', 'Users@Store'); $router->dispatch(); so after a bit of experimenting last night i found that if i removed the namespace and dont call by namespace and use and include file directly it calls the middleware as i saiid including files works calling namespace method doesnt even if i was to call App\Middleware\Auth and then call the middleware as Auth::class thanks againfrom phprouter.
Could you explain more, please? Is there still an issue?
If you use composer autoload no need to require/include anything manually.
from phprouter.
yes theres still an issue i have used dump autoload and it still causes this issue
thanks fir your response here is an image of my strucutre
here is a screen of my web.php
here is a pictiure of my auth middleware script
Now if i run it usingh the include file as above it will call the middleware no problem
now when i add namespace App\Middleware to Auth.php
and use App\Middleware\Auth in web.php
i ghet this error
from phprouter.
The issue is not about PhpRouter, it belongs to abusing PHP namespaces!
The middleware you have implemented has no namespace and you should add it this way:
<?php
namespace App\Middleware;
...
from phprouter.
yes theres still an issue i have used dump autoload and it still causes this issue
thanks fir your response here is an image of my strucutre
here is a screen of my web.php
here is a pictiure of my auth middleware script
Now if i run it usingh the include file as above it will call the middleware no problem
now when i add namespace App\Middleware to Auth.php
and use App\Middleware\Auth in web.php
i ghet this error
from phprouter.
yep ive already done that
and still getting same error
from phprouter.
Now if you check your IDE hints, Closure class is declared under \ namespace, so you have to add a use statement for it or you can add \ before it to use it. \Closure
from phprouter.
from phprouter.
Ok so thanks for your support andas i said its an amazing script you have wrote kudos to you the /closure worked and thanks for that peice of informarmation
from phprouter.
sorry i do have one question with this script does it have the ability to use the name as a url forwarder like laravel does when it used router(user.post) for example
from phprouter.
Yes, https://github.com/miladrahimi/phprouter#route-name
from phprouter.
Related Issues (20)
- Container: Reflection failed HOT 3
- Middleware HOT 5
- Obtaining QueryString Data HOT 5
- Question Again HOT 12
- Middleware: inject header in next HOT 10
- Is it possible to pass parameters to middleware? HOT 2
- Can you nest middleware? HOT 1
- About $url->make() HOT 2
- Get current request object or at least requested url, when 404 or any other error occurs? HOT 1
- Question about obtaining list or urls from web file and the method type HOT 7
- Uncaught ReflectionException HOT 1
- اجرای route بعدی HOT 1
- How to pass the 404 pages as view HOT 1
- Group routes: Unable to access route where path is set as prefix root HOT 3
- Feature request: Override method
- QueryStringData Revisited HOT 3
- Language prefix HOT 2
- Distinguish between HTTP 404 and 405
- PHP Version HOT 1
- Single Route file for multiple controller files/classes HOT 1
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 phprouter.