izniburak / php-router

PHP Router, which also has rich features like Middlewares and Controllers is simple, useful and flexible router class for PHP.
https://github.com/izniburak/php-router/wiki
MIT License
238 stars 45 forks source link

routes don't work #31

Closed NeftaliAcosta closed 4 years ago

NeftaliAcosta commented 4 years ago

I have the following directory tree:

project ├── app │ ├── controllers │ │ └── routeControllers.php │ ├── models │ ├── templates │ │ └── homeTemplate.php │ ├── pages │ │ ├── home.php │ │ ├── about.php │ │ └── contact.php ├── include │ │ ├── system.php ├── resources ├── vendor ── index.php

1.- index.php includes system.php 2.- system.php loads the libraries and calls the system controller.

<?php

    /**
     * Requiere los controladores y librerias
     */
    require_once __DIR__.'/../app/auto_loader.php';
    /**
     * Requiere las librerias de composer
     */
    require_once __DIR__.'/../vendor/autoload.php';

    require_once 'config.php';
    Use App\Controllers\route;
    $init = new route();
    $init->pages();

3.- The system controller instantiates the route controller e requires the main template:

<?php 

    namespace  App\Controllers;

    use App\Controllers\Route;

    class route{
        private $route;

        public function __construct(){
            $this->route =  new \Buki\Router();
        }

        public function pages(){

            /**
             * Rutas predeterminadas del sistema
             */
            $this->route->get('/', function() {
               echo "home";
            });

            $this->route->get('/hola/{s}', function($value) {
                echo "error".$value;
            });

            $this->route->error(function() {
                echo "error";
            });

            $this->route->run();
        }
    }

4.- when accessing the path / hello / world the url is not detected by the controller

image

Edit: if I use the following structure it works without problem:

$this->route->get('/hello/:string', function($value){
  echo 'Hello, ' . $value;
});
izniburak commented 4 years ago

Hi @NeftaliAcosta , Probably, this problem related with base_path. What is your base_path? You can try to change Router config. You can check out documentation.

Thanks.

NeftaliAcosta commented 4 years ago

Hi @NeftaliAcosta , Probably, this problem related with base_path. What is your base_path? You can try to change Router config. You can check out documentation.

Thanks.

It only works like this:

$this->route->get('/hello/:string', function($value){ echo 'Hello, ' . $value; });

izniburak commented 4 years ago

Everything seems normal. I couldn't understand the issue. Maybe it can be debugged for finding the problem. Did you share your project as public anywhere? Maybe, I can investigate it at a convenient time.

NeftaliAcosta commented 4 years ago

Everything seems normal. I couldn't understand the issue. Maybe it can be debugged for finding the problem. Did you share your project as public anywhere? Maybe, I can investigate it at a convenient time.

I created an example of the project so you can download it. https://github.com/NeftaliAcosta/proyecto.com.mx

The file in question is: /app/routes/oferta_route.php

Thanks for your time and your help.

NeftaliAcosta commented 4 years ago

I've already tried many things and can't get it to work :(

NeftaliAcosta commented 4 years ago

@izniburak I tell you the following: I have a project that I did 3 months ago, I copied and pasted the entire vendor / izniburak folder in my new project and now the routes already work using:

{a} => All chars without '/' char. {d} => Digits. {i} => Digits. {s} => Alphabetic characters. {w} => Alphanumeric characters. {u} => URL format characters for SEO. (Alphanumeric characters, _ and -) {*} => All characters

I think it is a problem of some update.

izniburak commented 4 years ago

@NeftaliAcosta Which version you used? Maybe we can compare it with latest version. But, I don't think that the problem is related with patterns.