0
我剛開始學習Symfony。事實是,我做的事情,他們的工作,但我不明白我在做什麼,這一定是錯誤的方式開始學習的東西。在Symfony中創建第一個控制器
下面是一個簡單的控制器:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
那是什麼:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class HelloController extends Controller
{
/**
* @Route("/hello")
*/
public function helloAction() {
return $this->render('', array());
}
}
在當我輸入
/**
* @Route("/hello")
*/
我的編輯器會自動添加這行代碼這種情況下
所以在做什麼?
我知道命名空間必須與目錄路徑相匹配,但我無法在Symfony項目中找到該路徑。那麼它是否在我的項目之外?如果是這樣,這將是很好的知道,如果我想上傳我的項目在Web服務器上。
如果有人能解釋這個「神祕」,我將不勝感激。
'Route'類位於供應商文件夾內,您的項目的代表處在哪裏。 – Federkun
您剛剛爲您的'helloAction()'定義了一個參數'@ Route'。要正常工作,它需要位於'Sensio \ Bundle \ FrameworkExtraBundle \ Configuration'中的類Route。這就是它被添加的原因。 – Preciel