php - Need Assistance with Symfony 2.7 creating first page -
i trying learn symfony framework , struggling it. instructions not helpful or assume know lot more know. trying create single web page proper route , controller. have been googling find answers , made progress no luck yet. right have standard install of symfony default bundles etc. created project called "gtest3" , chose php it...
i not sure put new route in (what file) or maybe needs put in more 1 file?
i found "routing.yml" file seems need put it...
here in there right now:
gtest3: resource: "@gtest3bundle/resources/config/routing.php" prefix: / app: resource: "@appbundle/controller/" type: annotation
i guessing need add , put location/filename of controller? have tried doing few ways , errors.
there "routing.php" file referenced in above code. not sure if "controller" or if additional piece of "route". here code file:
use symfony\component\routing\routecollection; use symfony\component\routing\route; $collection = new routecollection(); $collection->add('gtest3_homepage', new route('/hello/{name}', array( '_controller' => 'gtest3bundle:default:index', ))); return $collection;
i not sure if add here. - there "defaultconroller.php" file found may controller. dont think need include code of file here.
so - trying create route of maybe "/gman" , have controller echo on page. super basic stuff. , cannot figure out how going.
can this? much...
you can define routes in 3 ways, either using yml files, xml files, or using php file. documented behaviour.
you looks of routing.yml
trying set php version. not recommend it, , instead use configuration on coding routing.
the annotation example like:
adding controller:
namespace gtest3bundle\controller; use symfony\bundle\frameworkbundle\controller\controller; use sensio\bundle\frameworkextrabundle\configuration\route; class gtest3bundle extends controller { /** * @route("/hello/{name}") * @template() */ public function indexaction($name) { return array('name' => $name); } }
and add in app/config/routing.yml
:
gtest3: resource: "@gtest3rights/controller/" type: annotation prefix: /what-ever-you-want
you can check kind of routes have defined using:
./app/console router:debug
if doesn't appear hear, have misconfigured.
please advised bundle names breaks convention of how bundles should named in symfony2 context.
it advised use namespaceprojectbundle
. documented. if stuck, try generating bundle via ./app/console generate:bundle
. way can create whole symfony2 structure should show default page hello/foo page fine.
if doesn't seem run @ all, make sure have registered bundle @ in app/appkernel.php
file in registerbundles()
method.
Comments
Post a Comment