I’ve been trying to get rid of the getControllerConfig() Method, and move it over to the Module’s module.config.php.
Sadly, in the progress of doing so, I am encountering this error:
A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
Project\Controller\ProjectController (resolves to invalid controller class or alias: Project\Controller\ProjectController)
No Exception available
My Module.php:
<?php
namespace Project;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
use Project\Controller\Factory\ProjectControllerFactory;
use Project\Model\Factory\ProjectTableFactory;
use Project\Model\Factory\ProjectTableGatewayFactory;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
// public function getControllerConfig()
// {
// return [
// 'factories' => [
// Controller\ProjectController::class => ProjectControllerFactory::class
// ],
// ];
// }
}
The usage of namespace and classnames are wrong. You set the namespace to Project and then you use for the controller Project\Controller\ProjectController::class.
The result is: Project\Project\Controller\ProjectController::class
You’re fast, thanks!
That line is under defaults beneath router, right?
Error is still there. (For good measure, I composer dump’ed autoload and restarted the php dev server)
Updated file:
The composer config, the paths, the filenames, the namespaces and the class names are looking good so far.
module\Project\src\Controller\ProjectController.php:
<?php
namespace Project\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use Project\Model\ProjectTable;
use Project\Form\ProjectForm;
use Project\Model\Project;
use Laminas\Json\Encoder;
use InvalidArgumentException;
use Project\Form\UploadForm;
use Project\Form\Validator\DirectoriesCreated;
class ProjectController extends AbstractActionController
{
private $table;
<?php
namespace Project\Controller\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Project\Controller\ProjectController;
use Project\Model\ProjectTable;
class ProjectControllerFactory implements FactoryInterface {
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
No, that does not work. The config object uses internal an array as storage and the magic methods for setter and getter. Without special comments it does not help.
There are some attempts to solve this via extensions of IDEs, like:
This works for PHP arrays but at the moment it does not help with schemas from multiple classes or comments.
And in the end, it’s also only a workaround.
I would not make this dependent on a framework or a special tool like an extension, it should be available everywhere.
Wow, these plugin look awesome. I might be giving them a try somewhen.
In the end, you’re right again; there should be some sort of universally available solution. If a language server implemented that, that’d get pretty close to an independent tool. Maybe some folks end up adapting one of the deep assoc plugins for the IDEs.