Its possible to access more than one method from router ?
Pok4 opened this issue · comments
- PHPRouter version: 1.2alpha
- PHP version 7.4
Hello guys, i have a question about the routers, this one:
'_controller' => 'App\Controllers\BaseController::__construct',
works.
but this one:
'_controller' => 'App\Controllers\BaseController::__construct::the_tickets::ajax',
not works...
i check in base controller with class_exists('the_tickets') and it shows true...
My question is about can i access more than one method in routing...
Thank you for any replies.. :)
Hi again ;)
You simply cannot map multiple methods as controller.
When you create a Router, you want to map One Url to One controller.
I don't know what you want to achive with this, but at least in this library, you cannot map multiple methods on one route.
Awww... This is very important for my CMS... It's about extensions, they are load in construction method and i want to make ajax calls for them in their own classes...
For example:
<?php
namespace App\Controllers;
class BaseController {
public function __construct() {
require_once...(ext.php);
}
};
ext.php:
class the_tickets extends \App\Controllers\BaseController {
public function __construct() {
parent::__construct();
}
public function ajax() {
echo 1;
die();
}
};
$load_ext = new the_tickets;
$load_ext->load();
and i try with:
'_controller' => 'App\Controllers\BaseController::__construct::the_tickets::ajax',
I want to make ajax calls in exact same controller for specific extension. They are separate from the system and can enable or disable via admin panel.
Is there absolutely no chance, it is very important to me?
It is just not how it works, a router is not a way of calling multiple methods.
BUT, you should map like this :
'_controller' => 'App\Controllers\the_tickets::ajax'
It will call "new the_tickets()" by itself, then call your ajax method.
(Replace App\Controllers by the correct namepsace of "the_tickets")
the problem is that the extensions is in a different folder, called 'ext'
The path is like this: www/ext/pok4/the_tickets and the classes not using namespaces...
can you give me a solution for what i want ? :)
I'm afraid I can't, you have problems that are more related to your app structure than the library features.
If you need help to code your extension, you may ask the developers of the base software instead.
ok, thank you!