symfony - Symfony2 + inject static class -


i'm new here , hope question not trivial.

i have package static class in (a grid builder) , want use in symfony2

so know class loading , service container don't container work.

the grid class depending on 2 other static classes (one configuration , 1 sql query´s)

the code use class following:

$grid = grid::get_instance(); $grid->table('products'); echo $grid->rendergrid(); 

and internally class uses calls gridconfig::database() - thought maybe cann add 3 classes service.yml doesn't anything.

so question is: how can inject static class in way can use in controller? possible , if yes best practice case it?

thank help.

since static there no need inject it. like:

$grid = \grid::get_instance; 

should work. if grid uses namespaces need add well. , need ensure autoloader can find it.

of course using globals kind of frowned up. can write own service act wrapper.

class mygridservice  {     protected $grid;      public function getinstance()     {         if (!$this->grid) $this->grid = \grid::get_instance();         return $this->grid;     } } 

add mygridservice services.yml file controller can do:

$grid = $this->get('my_grid_service')->getinstance(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -