php - Symfony : why am I not allowed to combine "type" with "defaults" in routing.yml -


short version of question : symfony's error message explains cannot use type key in conjunction defaults, can use resources (see details below). why ? how can fix ?

detailed version :

here exact sequence of did in symfony :

composer create-project symfony/framework-standard-edition sym-book/ '~2.5' php app/console generate:bundle --namespace=middleman/bookbundle --format=yml 

edit contents of src/middleman/bookbundle/resources/config/routing.yml to

middle_man_book_example:     path:     /example     defaults: { _controller: middlemanbookbundle:lucky:number }     type: annotation 

in directory src/middleman/bookbundle/controller, rename defaultcontroller.php luckycontroller.php, , edit contents to

namespace middleman\bookbundle\controller;  class luckycontroller {     /**      * @route("/lucky/number")      */     public function numberaction()     {         $number = rand(0, 100);          return new response(             '<html><body>lucky number: '.$number.'</body></html>'         );     } } 

type localhost:8000/example/lucky/number in browser.

the error message follows :

the "type" key route definition "middle_man_book_example" in  "/users/ewandelanoy/documents/math_software/symfony_stuff/sym-book/src/middleman/bookbundle/resources/config/routing.yml"  unsupported. available imports in combination  "resource" key in  /users/ewandelanoy/documents/math_software/symfony_stuff/sym-book/src/middleman/bookbundle/resources/config/routing.yml ( being imported "/users/ewandelanoy/documents/math_software/symfony_stuff/sym-book/app/config/routing.yml") 

if using type: annotation don't need, and, actually, must not, store defaults section in routing.yml. defaults section configured each route in own annotation, route annotation like:

/**  * sample route  * @route("/{id}", name="sample-route-name", defaults={"id" = 1})  * //defaults section there provide default values  *  * @method({"get", "post"}) // not needed, default -  */ 

and yml routing configuration like:

sample_bundle_routing:     resource: "@yourbundle/controller/"     type:     annotation     prefix:   /some_prefix/ 

upd yml config should put in main routing.yml. use variant. in main routing.yml put this:

sample_bundle_routing:     resource: "@yourbundle/resources/config/routing.yml" 

then in routing.yml put in main routing.yml resource can write:

sample_bundle_routing:     resource: "@yourbundle/controller/"     type:     annotation     prefix:   /some_prefix/ 

i have question: why need use both yml , annotation routing config? mean write in comment below: "but need edit routing.yml file in directory also, give controller name , action method name.". if use annotation routing type - there no need configuration annotation routing in yml. mean: routing either annotations each action or strings in bundle/main routing.yml, not both @ same time! if use annotation routing, thing need put in yml - routing config (in example "@yourbundle/controller/" path).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -