SymfonyブログチュートリアルをSymfony2.3でやった時に引っかかるところ

他にも同じようなことを書いている場所もありましたが、全てを網羅しているところがなかったので、僕も書いておきます。

blogチュートリアル(8) データのバリデーション

[Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\MaxLength" in property My\BlogBundle\Entity\Post::$title does not exist, or could not be auto-loaded.


@Assert\MaxLength(50)
@Assert\MinLength(10)となっているところは書き方が変わっていて、
@Assert\Length(max = "50")
@Assert\Length(min = "10")
とする。

カスタマイズ編(3) フラッシュメッセージの表示

FatalErrorException: Error: Call to undefined method Symfony\Component\HttpFoundation\Session\Session::setFlash()




$this->get('session')->setFlash('my_blog', '記事を追加しました');

$this->get('session')->getFlashBag()->set('my_blog', '記事を追加しました');
に変更

また、

Method "hasFlash" for object "Symfony\Component\HttpFoundation\Session\Session" does not exist in MyBlogBundle:Default:index.html.twig at line 3

には、
{% if app.session.hasFlash('my_blog') %}
<div style="background-color:yellow;color:red;font-weight:bold;"> 
 {{ app.session.flash('my_blog') }} 
</div> 
{% endif %}

{% for flashMessage in app.session.flashbag.get('my_blog') %}
<div style="background-color:yellow;color:red;font-weight:bold;">
{{ flashMessage }}
</div>
{% endfor %}
に変更。
Symfony2.3でsessionのflashデータの操作方法が変わった件 | ななうぇぶのブログ

コメント

このブログの人気の投稿

2次元配列のコピー::JavaScript

iframeの利点と欠点

chromyを実行するとエラー:"Failed to launch a browser"が出る