Welcome Guest, Not a member yet? Register   Sign In
Route call wrong method
#7

(05-04-2021, 10:45 AM)iRedds Wrote: Sorry. I’m completely blind.

The problem is that under the route
$routes->delete('(:any)', 'Media::delete/$1');
fits
DELETE admin/media and DELETE admin/media/directory

You need to change the order of the routes.

first
$routes->delete('directory/(:any)', 'Media::directory/$1');
next
$routes->delete('(:any)', 'Media::delete/$1');

You're using
route_to('admin/media/files')
But the route is completely different
admin/media/files/(:any)/details

The route_to function does not find it.
In addition, you have an undefined segment, so route_to will also throw an exception.

With your route, it is more correct to define the route alias.
for example
PHP Code:
$routes->get('admin/media/files/(:any)/details''Controller::method', ['as' => 'files.details']);
// and call 
route_to('files.details'123); // admin/media/files/123/details 

But since your segment is dynamic and the code is executed on the client, you cannot use route_to().
And it is better to form the URL manually.

Thanks for the answer, I have changed my routes in this configuration now:

PHP Code:
$routes->group('media', [
        
'filter'         => 'permission:manage-media',
        
'namespace'        => 'App\Controllers',
        
'controller'    => 'Media',
        
'except'        => 'show'
    
], function ($routes) {

        
$routes->get('/''Media::index');
        
$routes->get('(:num)''Media::details/$1');
        
$routes->get('filter''Media::filter');
        
$routes->delete('(:num)''Media::delete/$1');
        
$routes->post('move''Media::move');
        
$routes->put('(:any)''Media::update/$1');

        
// meta
        
$routes->get('meta/(:any)''Media::getMeta/$1', ['as' => 'media.meta']);

        
// directory
        
$routes->get('directory''Media::directory');
        
$routes->post('directory''Media::directory');
        
$routes->delete('directory/(:any)''Media::directory/$1');
    }); 

now the only problem that I get is on meta/(:any), so if I do this:

PHP Code:
url: `<?= base_url('admin/media/meta') ?>/${type}`, 

everything works fine, but if I do this:


PHP Code:
url: `<?= route_to('admin/media/meta') ?>/${type}`, 

the function route_to return an empty string
Reply


Messages In This Thread
Route call wrong method - by sfarzoso - 05-03-2021, 10:37 AM
RE: Route call wrong method - by iRedds - 05-03-2021, 12:01 PM
RE: Route call wrong method - by sfarzoso - 05-04-2021, 12:37 AM
RE: Route call wrong method - by sfarzoso - 05-04-2021, 02:14 AM
RE: Route call wrong method - by iRedds - 05-04-2021, 10:45 AM
RE: Route call wrong method - by sfarzoso - 05-05-2021, 12:54 AM
RE: Route call wrong method - by paliz - 05-04-2021, 11:15 AM
RE: Route call wrong method - by InsiteFX - 05-05-2021, 05:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB