Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向其他控制器转发请求不起作用-symfony4_Php_Controller_Symfony4 - Fatal编程技术网

Php 向其他控制器转发请求不起作用-symfony4

Php 向其他控制器转发请求不起作用-symfony4,php,controller,symfony4,Php,Controller,Symfony4,我的问题是,将请求转发到另一个控制器不起作用 我已经尝试了symfony文档()中的解决方案/示例 IndexController.php <?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; class IndexController extend

我的问题是,将请求转发到另一个控制器不起作用

我已经尝试了symfony文档()中的解决方案/示例

IndexController.php

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    /**
     * @Route("/", name="app_index_index")
     */
    public function index($thisname)
    {
        $thisname = "TEST";

        return $this->render('index/index.html.twig', [
            'controller_name' => 'IndexController',
            'pagetype' => 'index',
            'pageurl' => "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
        ]);
    }
}
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Offnungszeiten;

class OeffnungController extends AbstractController
{
    /**
     * @Route("/oeffnung/show", name="app_oeffnung_show")
     */
    public function show()
    {
        $product = $this->getDoctrine()
            ->getRepository(Offnungszeiten::class)
            ->findOneBy(['name' => 'TESTPRODUCT']);

        if (!$product) {
            throw $this->createNotFoundException(
                'No product found for id '
            );
        }

        $response = $this->forward('App\Controller\IndexController::index', [
            'thisname' => 'name',
        ]);

        return $response;
    }
}

OeffnungController.php

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    /**
     * @Route("/", name="app_index_index")
     */
    public function index($thisname)
    {
        $thisname = "TEST";

        return $this->render('index/index.html.twig', [
            'controller_name' => 'IndexController',
            'pagetype' => 'index',
            'pageurl' => "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
        ]);
    }
}
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Offnungszeiten;

class OeffnungController extends AbstractController
{
    /**
     * @Route("/oeffnung/show", name="app_oeffnung_show")
     */
    public function show()
    {
        $product = $this->getDoctrine()
            ->getRepository(Offnungszeiten::class)
            ->findOneBy(['name' => 'TESTPRODUCT']);

        if (!$product) {
            throw $this->createNotFoundException(
                'No product found for id '
            );
        }

        $response = $this->forward('App\Controller\IndexController::index', [
            'thisname' => 'name',
        ]);

        return $response;
    }
}

我犯了以下错误

Could not resolve argument $thisname of "App\Controller\IndexController::index()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?

刚刚从
OeffnungController::show
方法中删除了未使用的
$thisname
参数,并填充了注释。这对我很有用

IndexController.php

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
    /**
     * @Route("/", name="app_index_index")
     */
    public function index($thisname)
    {
        $thisname = "TEST";

        return $this->render('index/index.html.twig', [
            'controller_name' => 'IndexController',
            'pagetype' => 'index',
            'pageurl' => "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
        ]);
    }
}
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Offnungszeiten;

class OeffnungController extends AbstractController
{
    /**
     * @Route("/oeffnung/show", name="app_oeffnung_show")
     */
    public function show()
    {
        $product = $this->getDoctrine()
            ->getRepository(Offnungszeiten::class)
            ->findOneBy(['name' => 'TESTPRODUCT']);

        if (!$product) {
            throw $this->createNotFoundException(
                'No product found for id '
            );
        }

        $response = $this->forward('App\Controller\IndexController::index', [
            'thisname' => 'name',
        ]);

        return $response;
    }
}

是否要按参数创建自定义布线?是否在“/”上发送请求并根据此参数将其转发给另一个控制器?