symfony - Can I implement my own Symfony2 annotations easily? -
is there in symfony annotations modules allow me use them other uses? know @route , @method need extend existing libraries, not easy im guessing.
currently, im working history api, , love put popstate data javascript files in annotations, available when routing generates url, makes sense have html5 annotated title here doesn't it?
it great put next existing route name , stuff. there has tweaked annotations before?
edit im going clarify intentions here left out crucial details understanding motive, thought more clear.
ok, use alot of ajax on symfony2 app. use fosjsrouter handle routing. instead of urls triggering routes , actions, spa have click events triggering run route using ajax, passing param data php methods directly way.
so given this, have nice js object method runs ajax call, , passes json around , backend. inside method im focusing on being best place add historyapi functionality it, button.
im thinking ajax method perfect place if history flag called, , populate historys state data right here , inside method. place because json data object im passing around in js method contains alot of crucial route data, , param information route needed in backend php, comes annotations. if add history state title, , url annotation, have access information right there available create nice history state, if flagged, right inside ajax.done() inside main js routing method.
edit: can 1000+ rep please add history-api tag since code examples annotating using this.
edit i'm not sure that's thinking, looks making me set values of title , url inside return statement of php function, want set in annotation (see return 'matthias noback';
)
so im trying this, set these titles at?
<?php namespace blah\corebundle\controller; use symfony\bundle\frameworkbundle\controller\controller; /** * @annotation */ class historyannotationcontroller { //history state params out properties here.. /** * @var */ private $url; /** * @var */ private $title; /** * */ public function __construct() { } /** * @return mixed */ public function gettitle() { return $this->title; } /** * @return mixed */ public function geturl() { return $this->url; } }
i want set way here, ajax calls route has access it.. (look @historyapititle in code, etc..)
<?php namespace blah\bundle\controller; use symfony\bundle\frameworkbundle\controller\controller, symfony\component\httpfoundation\jsonresponse, sensio\bundle\frameworkextrabundle\configuration\method, sensio\bundle\frameworkextrabundle\configuration\route, sensio\bundle\frameworkextrabundle\configuration\template, blah\bundle\entity\test, doctrine\orm\query; //for hydration class stuffcontroller { /** * @route("/some/route/name/{test}", name="some_route_name", options={"expose"=true}) * @param $test * @return mixed * @historyapititle('this page') * @historyapiurl('/get_something') */ public function getsomethingaction($test) { $em = $this->getdoctrine()->getmanager(); $dql = " select s blahbundle:stuff s s.test = :test"; $query = $em->createquery($dql); $query->setparameter('test', $test); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($query, $this->get('request')->query->get('page', 1), 1000); return $this->render('blahbundle:stuff:get_something.html.twig', array('pagination' => $pagination)); } }
so looking @ these 2 code examples, how connect dots between 2 work?
yes can annotations classes can follow following tutorial creating custom annotations classes
basic rules follows:
your class should have
@annotation
-phpdoc comment/** * @annotation */ class customannotation { public function __construct($options) {} }
in needed class use in standard way;
class person { /** * @customannotation("option") */ public function getname() { return 'some stuff'; } }
Comments
Post a Comment