Giter Site home page Giter Site logo

Comments (12)

miladrahimi avatar miladrahimi commented on August 26, 2024

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.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

image

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 again

from phprouter.

miladrahimi avatar miladrahimi commented on August 26, 2024

Could you explain more, please? Is there still an issue?
If you use composer autoload no need to require/include anything manually.

from phprouter.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

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

image

here is a screen of my web.php
image

here is a pictiure of my auth middleware script

image

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

image

web.php
image

from phprouter.

miladrahimi avatar miladrahimi commented on August 26, 2024

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.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

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

image

here is a screen of my web.php
image

here is a pictiure of my auth middleware script

image

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

image

web.php
image

from phprouter.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

yep ive already done that

image

and still getting same error

from phprouter.

miladrahimi avatar miladrahimi commented on August 26, 2024

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.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

from phprouter.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

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.

mbamber1986 avatar mbamber1986 commented on August 26, 2024

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.

miladrahimi avatar miladrahimi commented on August 26, 2024

Yes, https://github.com/miladrahimi/phprouter#route-name

from phprouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.