Showing posts with label Symblog. Show all posts
Showing posts with label Symblog. Show all posts

Tuesday, September 8, 2015

Build a blog bundle with Symfony 2 - Symblog tutorial errors/deprecated functions

Symblog tutorial ( http://tutorial.symblog.co.uk/ ) is one of the best I found about developing and testing a Symfony 2 bundle.
But is not all perfect, some of the function used in the tutorial are deprecated and will not work.
I found another blog were some of the issues are solved:
 http://donna-oberes.blogspot.com/2013/09/symfony-2-symblog-tutorial-errors.html

Please see below a list comments that you help you finish the tutorial successfully.
I hope this blog post will help some fellows lost  in the path of learning Symfony 2.

1. In controller repalce "bindRequest()" deprecated function with "bind()"

public function contactAction()
    {
        $enquiry = new Enquiry();
        $form = $this->createForm(new EnquiryType(), $enquiry);
       
        $request = $this->getRequest();
        if ($request->getMethod() == 'POST') {
            $form->bind($request);


2. I stoled this from a comment on the Symblog website:

FYI for symfony2.3 (and 2.4) users:

{% if app.session.hasFlash('blogger-notice') %}
<div class="blogger-notice">
{{ app.session.flash('blogger-notice') }}
</div>
{% endif %}


needs to be changed to

{% for flashMessage in app.session.flashbag.get('blogger-notice') %}
<div class="blogger-notice">
{{ flashMessage }}
</div>
{% endfor %}


Also you need to change the “setFlash” in PageController to call  “getFlashBag()->add”


3. Doctrine basic usage in official documentation:

http://symfony.com/doc/current/book/doctrine.html

4. In  BlogController:

DEPRECATED - getEntityManager is deprecated since Symfony 2.1. Use getManager instead

Change path to images in show.htmltwig. it should point to specific bundle folder in the public "web" folder:

 <img src="{{ asset(['bundles/bloggerblog/images/', blog.image]|join) }}


5. Doctrine migrations

http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html

$ composer require doctrine/doctrine-migrations-bundle "^1.0"

In AppKernel.php you need to change this

new Symfony\Bundle\DoctrineMigrationsBundle\DoctrineMigrationsBundle() //old path

with this

new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()


----------------------------------------------------------------------------------------------------------
Some errors messages that may make you land on this page:

FatalErrorException: Error: Call to undefined method Symfony\Component\Form\Form::bindRequest() in /path/to/root/src/Blogger/BlogBundle/Controller/PageController.php 
FatalErrorException: Error: Class 'Symfony\Component\Validator\Constraints\MaxLength' not found in /path/to/root/src/Blogger/BlogBundle/Entity/Enquiry.php