简体   繁体   中英

Symfony passing 'login' to default parameter of route

I added a default parameter to the route that is called after a user is authenticated. After running doctrine:fixtures:load to load new data I refreshed the page expecting it to take me to the login screen. However, it seems to be calling the route and passing 'login' to the default parameter.

    /**
     * @Route("/{sortOrder}", name="patient_order_index")
     * @param PatientOrderRepository $patientOrderRepository
     * @param $sortOrder
     * @return Response
     */
    public function index(PatientOrderRepository $patientOrderRepository, string $sortOrder = null)
    {

        $patients = $patientOrderRepository->getPatientsWithOrders($sortOrder);

        return $this->render('patient_order/index.html.twig', [
            'patient_orders' => $patients, 'sortOrder' => $sortOrder
        ]);
    }

I've tried checking to see if $sortOrder was = 'login' then redirecting and checking if user was fully authenticated but both sent me in infinite redirects.

Ended up needing two separate routes with different route names.

     * @Route("patient_order/orders/{sortOrder}", name="patient_order_index")
     * @Route("/", name="default_homepage")
     * @param PatientOrderRepository $patientOrderRepository
     * @param $sortOrder
     * @return Response
     */
    public function index(PatientOrderRepository $patientOrderRepository, string $sortOrder = null)
    {

        if($sortOrder == null) {
            $sortOrder = 'ASC';
        }

        $patients = $patientOrderRepository->getPatientsWithOrders($sortOrder);

        return $this->render('patient_order/index.html.twig', [
            'patient_orders' => $patients, 'sortOrder' => $sortOrder
        ]);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM