- ดาวน์โหลด http://symfony.com/download เเล้วมาวางที่เราจำลองเซิร์ฟเวอร์ จากนั้นก็ รัน http://localhost/hwsymfony/web/app_dev.php/
Symfony 2 framework : สร้างไฟล์ Hello World 1. สร้าง path ไว้สำหรับเรียกไฟล์ Resources > config > routing.yml
โค้ด: เลือกทั้งหมด
_hello:
resource: "@AcmeDemoBundle/Controller/helloController.php"
type: annotation
จากนั้น
โค้ด: เลือกทั้งหมด
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Acme\DemoBundle\Form\ContactType;
// these import the "@Route" and "@Template" annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* @Route("/hello")
* @Template()
*/
class helloController extends Controller
{
/**
* @Route("/", name="_demo")
* @Template()
*/
public function indexAction()
{
return array();
}
}
โค้ด: เลือกทั้งหมด
/**
* @Route("/hello")
* @Template()
*/
4. สร้างไฟล์ .twig (ไฟล์เทมเพลต)
โค้ด: เลือกทั้งหมด
{# empty Twig template #}
Hello World