Replies: 2 comments
-
when I manipulate and add a route to the router, it works well, like this: foreach ($modules as $module) { return $router; Is it possible that it has been packaged in other non-open source packages? |
Beta Was this translation helpful? Give feedback.
-
The project you chose is quite old. It uses Phalcon 3.4 and we are now at 5.0. I would suggest checking our organization's repositories and using a sample from there. The rest-api, vokuro, invo repos are a good starting point. In general, for your application to find files you need to ensure that you have a namespace in each class and each file is located in the folder structure that you have defined. Alternatively, you will need to set up your autoloader to point to whatever folder you have your files in. This way the files will be loaded as needed. |
Beta Was this translation helpful? Give feedback.
-
This is my first time using Phalcon. I pulled an open-source project on GitHub ( https://github.com/xiaochong0302/course-tencent-cloud ) and will add an API router. I added an action to the original controller class, but it didn't work. Can anyone tell me why?
Route register code:
$router = new Router(false);
//$router = new Phalcon\Mvc\Router(true);
$router->removeExtraSlashes(true);
$router->setDefaultNamespace('App\Http\Home\Controllers');
$router->notFound([
'module' => 'home',
'controller' => 'error',
'action' => 'show404',
]);
$modules = ['api', 'home', 'admin'];
foreach ($modules as $module) {
$moduleName = ucfirst($module);
$files = scandir(app_path('Http/' . $moduleName . '/Controllers'));
foreach ($files as $file) {
if (preg_match('/^\w+Controller.php$/', $file)) {
$className = str_replace('Controller.php', '', $file);
$router->addModuleResource($module, 'App\Http\' . $moduleName . '\Controllers\' . $className);
}
}
}
I added a new function to exist named "course" class, like this :
public function codeAction()
{
$service = new CourseListService();
$pager = $service->handle();
return $this->jsonPaginate($pager);
It doesn't work, but in this class other existing functions work well.
/**
* @get("/list", name="api.course.list")
*/
How do we resolve this route problem? Thanks very much
Beta Was this translation helpful? Give feedback.
All reactions