Do you have a ServiceConfig for Application\Form\AddjobForm in Module.php?
public function getServiceConfig(): array
{
return [
\Application\Form\AddjobForm::class => function( $sm ) {
return new \Application\Form\AddjobForm(
#You can use $sm->get(\Other\Class::class) for DI in your constructor.
);
}
];
}
I hope that it is what you mean. I am a Newbie in Laminas but it is a great framework
Not needed here and also should avoided. If no separate factory for the form is needed then you need no extra registration. See the description for application integration from above for more details.
I decided to use the Application module itself instead of creating a separate module. This was done just for study purposes. And I feel the issue I am facing has something to do with that.
I have not registered a factory for this since I am directly using the new operator to create the AddjobForm instance. Please refer to the screenshot of the error message below. It appears to be dumping code from the AddjobForm class.
Message:
Class ‘Application\Form\AddjobForm’ not found
Code for Application\src\Form\AddjobForm.php
namespace Application\Form;
use Laminas\Form\Form;
class AddjobForm extends Form
{
public function __construct($name = null)
{
parent::__construct('jobsummary');
$this->add([
'name' => 'jobid',
'type' => 'hidden',
]);
...
Code for Application\src\Controller\IndexController.php
I was expecting that IndexController would be able to resolve the AddjobForm class especially since it is explicitly declared with the use keyword.
namespace Application\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use Laminas\Form\Factory;
use Application\Model\JobsummaryTable;
use Application\Model\Jobsummary;
use Application\Form\AddjobForm;
class IndexController extends AbstractActionController
{
private $jobsummaryTable;
public function __construct(JobsummaryTable $jobsummarytable)
{
$this->jobsummaryTable = $jobsummarytable;
}
public function indexAction()
{
return new ViewModel([
'jobsummaries' => $this->jobsummaryTable->fetchAll(),
]);
}
public function addjobAction()
{
$form = new AddjobForm(); -- this is where i get the error. this is line no. 39
$request = $this->getRequest();
if(!$request->isPost())
{
//blank form
return ['form' => $form];
}
...