• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug in routes with path in controller

#1
Hi, Routes with pass parameters such as the following:
$routes->get('/movie/test/(:any)', 'dashboard/MovieController::test/$1');

They only work if the controller (for example MovieController) is in the root:
$routes->get('/movie/test/(:any)', 'MovieController::test/$1');



In the first case ($routes->get('/movie/test/(:any)', 'dashboard/MovieController::test/$1');) the error it gives is the following

404 - File Not Found
Controller or its method is not found: \App\Controllers\dashboard::index


It does not recognize the controller according to the error it throws; But if I remove the dasboard from the configuration like:

$routes->add('movie/test/(:any)', 'MovieController::test/$1');

its working
Reply

#2
You can use only

$routes->add('journals', 'App\Blogs'); if dashboard is files and it have controller you must use \ .Its run default index function.
$routes->add('blog/joe', 'Blogs::users'); if dashboard is controller you must use scope + function

you can see https://codeigniter4.github.io/userguide...uting.html
Sercan YANBULOGLU
SEO links REDACTED, per forum policy
Reply

#3
dashboard is a folder:

-Controllers (folder)
  -dashboard (folder)
    -MovieController (class PHP - controller)

I want to put the controllers of the administrative module inside a folder (dashboard) and in another folder my Rest Api (rest folder)

thank you!
Reply

#4
(11-25-2019, 04:41 AM)acy29 Wrote: dashboard is a folder:

-Controllers (folder)
  -dashboard (folder)
    -MovieController (class PHP - controller)

I want to put the controllers of the administrative module inside a folder (dashboard) and in another folder my Rest Api (rest folder)

thank you!

Dashboard folder must be with first upper case letter D. Try that, cause at least that was the case few month ago
Reply

#5
Am also experiencing the same issue with routes with parameters
PHP Code:
    $routes->group('usergroups', ['filter' => 'ajax'], function($routes){
        
$routes->add('(:num)/edit''Backend/Users::editGroup/$1', ['as' => 'edit_group']);
    }); 

This route is not working. Am getting 404 error. Controller method is not found: index

I have controller in:  App/Controllers/Backend/Users.php

PHP Code:
<?php 
namespace App\Controllers\Backend;

use 
App\Controllers\Backend;
use 
App\Models\Backend\UserModel;

class 
Users extends Backend
{
    protected $userModel;

    public function __construct(){
    
parent::__construct();
    
$this->userModel = new UserModel();
    }

    public function editGroup($groupId)    
    {
    
$data['group'] = $this->userModel->getGroupDetails($groupId);
    echo 
view'backend/users/edit_group'$data);
    }


how can i fix this issue?
Reply

#6
(11-30-2019, 05:41 AM)midhunlalkc Wrote: Am also experiencing the same issue with routes with parameters
PHP Code:
    $routes->group('usergroups', ['filter' => 'ajax'], function($routes){
        
$routes->add('(:num)/edit''Backend/Users::editGroup/$1', ['as' => 'edit_group']);
    }); 

This route is not working. Am getting 404 error. Controller method is not found: index

I have controller in:  App/Controllers/Backend/Users.php

PHP Code:
<?php 
namespace App\Controllers\Backend;

use 
App\Controllers\Backend;
use 
App\Models\Backend\UserModel;

class 
Users extends Backend
{
    protected $userModel;

    public function __construct(){
    
parent::__construct();
    
$this->userModel = new UserModel();
    }

    public function editGroup($groupId)    
    {
    
$data['group'] = $this->userModel->getGroupDetails($groupId);
    echo 
view'backend/users/edit_group'$data);
    }


how can i fix this issue?

It is because codeigniter is expecting all of your controllers to be in one folder, App/Controllers. If you try to reference it out of that, then it says it can't find it and throws a 404 error.

The solution is really simple, just tell it where the new namespace is:

$routes->add('(:num)/edit', 'Users::editGroup/$1', ['as' => 'edit_group', 'namespace' => 'App\Controllers\Backend']);

https://codeigniter4.github.io/userguide/incoming/routing.html#assigning-namespace

Hope that helps you solve your issue.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.