Symfony could not resolve argument

  Kiến thức lập trình

I’m supposed to list down database entries from mysql database tables. I’m using the following code:

use AppEntitySignal;
use AppFormSignalType;
use AppFormVerificationSignalType;
use AppFormTransitionSignalType;
use AppFormPlanningSignalType;
use AppFormResolutionSignalType;
use AppRepositorySignalRepository;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAttributeRoute;
use DoctrinePersistenceManagerRegistry;

#[Route('/signal')]
class SignalController extends AbstractController
{
    #[Route('/', name: 'app_signal_index', methods: ['GET'])]
    public function index($id): Response
    {
        $signal = $this->doctrine
        ->getRepository(Signal::class)
        ->find($id);
        return $this->render('signal/index.html.twig', [
            'signal' => $signal,
            'verification' =>  $signal->getVerification(),
            'transition' =>  $signal->getTransition(),
            'planning' => $signal->getPlanning(),
            'resolution' => $signal->getResolution(),
            
        ]);
    }
}

In the index:

<tbody>
    {% for signal in signals %}
        <tr>
            <td>{{ signal.id }}</td>
            <td>{{ signal.date ? signal.date|date('Y-m-d H:i:s') : '' }}</td>
            <td>{{ signal.address }}</td>
            <td>{{ signal.description }}</td>
            {% for transition in signals %}
                <td>{{ transition.priority }}</td>
            {% endfor %}
            <td>
                <div class="mt-3">
                    <div class="btn-group" role="group" aria-label="Basic example">
                        <a href="{{ path('app_signal_show', {'id': signal.id}) }}" class="btn btn-secondary" role="button">show</a>
                        <a href="{{ path('app_signal_edit', {'id': signal.id}) }}" class="btn btn-secondary" role="button">edit</a>
                    </div>
                </div>
            </td>
        </tr>
    {% else %}
        <tr>
            <td colspan="26">no records found</td>
        </tr>
    {% endfor %}
</tbody>

I’m trying to list the data from the database but i’m getting the following error:

Could not resolve argument $id of “AppControllerSignalController::index()”, maybe you forgot to register the controller as a service or missed tagging it with the “controller.service_arguments”?

LEAVE A COMMENT