【AngularJS】ng-clickディレクティブに関するメモ。

というかディレクティブ全般に関して。

ディレクティブ(ng-属性)内では通常のテンプレート部分とは違いAngular式の評価が行えるので、
例えばIDをパラメーターとして埋め込みたいときにも{{}}を用いる必要はない。

例。

これはダメ。

<a ng-click="submit({{data.id}})"></a>

これでいい。

<a ng-click="submit(data.id)"></a>

 

【AngularJS】指定のパスにリダイレクトする。

$locationオブジェクトを用いる。

$location.path('/path');

これで指定したパスに移動することが可能。

$locationオブジェクトの詳細は下記URLが参考になる。

http://js.studio-kingdom.com/angularjs/guide/$location

 

【Symfony2.3】prod環境のキャッシュを消す。

方法。

php app/console cache:clear --no-warmup --env=prod --no-debug

でいける。

 

【PHP】クラス内のメソッド一覧を取得する。

$methods = get_class_methods('myclass');
// or
$methods = get_class_methods(new myclass());

クラス名かクラスのインスタンスを渡せばOK。

 

【Symfony2.3】FOSRestBundleの使い方メモ。

シンプルにエンティティを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。

 

【Symfony2.3】FOSRestBundleをインストールする。

手順メモ。

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

 

【Symfony2.3】引数を要するルーティングに引数無しでもアクセス可にする方法。

例えば引数に名前が必要なURIに名前無しでアクセスさせたい場合。

hello_world:
    pattern: /hello/{name}
    defaults: { _controller: HogeBundle:Fuga:hello }
    requirements:
        name: ".+"

requirementsでnameのパターンを上記の様に指定してやればOK。

 

【Yaml】YMLファイルではタブ文字は使用禁止。

使用できるようにすることは出来るらしいけども、使わない方がいいね。