というかディレクティブ全般に関して。
ディレクティブ(ng-属性)内では通常のテンプレート部分とは違いAngular式の評価が行えるので、
例えばIDをパラメーターとして埋め込みたいときにも{{}}を用いる必要はない。
例。
これはダメ。
<a ng-click="submit({{data.id}})"></a>
これでいい。
<a ng-click="submit(data.id)"></a>
というかディレクティブ全般に関して。
ディレクティブ(ng-属性)内では通常のテンプレート部分とは違いAngular式の評価が行えるので、
例えばIDをパラメーターとして埋め込みたいときにも{{}}を用いる必要はない。
例。
これはダメ。
<a ng-click="submit({{data.id}})"></a>
これでいい。
<a ng-click="submit(data.id)"></a>
$locationオブジェクトを用いる。
$location.path('/path');
これで指定したパスに移動することが可能。
$locationオブジェクトの詳細は下記URLが参考になる。
http://js.studio-kingdom.com/angularjs/guide/$location
方法。
php app/console cache:clear --no-warmup --env=prod --no-debug
でいける。
$methods = get_class_methods('myclass'); // or $methods = get_class_methods(new myclass());
クラス名かクラスのインスタンスを渡せばOK。
シンプルにエンティティをjsonで出力する方法。
namespace Hoge\FugaBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Hoge\FugaBundle\Entity\Post; use FOS\RestBundle\Controller\FOSRestController; /** * Post controller. */ class PostController extends FOSRestController { /** * Lists all Post entities. */ public function indexAction(Request $request) { $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('HogeFugaBundle:Post')->findAll(); $view = $this->view($entities, 200)->setFormat('json'); return $this->handleView($view); } }
色々ハマったけどこれだけでOK。
手順メモ。
RestBundleはJMSSerializerBundleを必要とするのでまずJMSの方をインストールする。
php composer.phar require jms/serializer-bundle Please provide a version constraint for the jms/serializer-bundle requirement: dev-master
※バージョンは「dev-master」を指定
次にFOSRestBundleをインストールする。
php composer.phar require friendsofsymfony/rest-bundle 1.3.*
あとはカーネルで両方とも読みこめば完了。
詳細は下記URLを参照されたし。
http://jmsyst.com/bundles/JMSSerializerBundle
https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/index.md
例えば引数に名前が必要なURIに名前無しでアクセスさせたい場合。
hello_world: pattern: /hello/{name} defaults: { _controller: HogeBundle:Fuga:hello } requirements: name: ".+"
requirementsでnameのパターンを上記の様に指定してやればOK。
使用できるようにすることは出来るらしいけども、使わない方がいいね。