PHP code example of mb-x / architect-bundle

1. Go to this page and download the library: Download mb-x/architect-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mb-x / architect-bundle example snippets

 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Mbx\ArchitectBundle\MbxArchitectBundle(),
    );
}
 php

namespace AppBundle\Entity;

use Mbx\ArchitectBundle\Interfaces\EntityInterface;

class Post implements EntityInterface
{
    // ...
    
    public function getId()
    {
        return $this->id;
    }
    
    // ...
}
 php
    /**
     * Lists all post entities.
     *
     * @Route("/", name="post_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $posts = $this->get('appbundle.post_manager')->getRepository()->findAll();

        return $this->render('post/index.html.twig', array(
            'posts' => $posts,
        ));
    }

    /**
     * Creates a new post entity.
     *
     * @Route("/new", name="post_new")
     * @Method({"GET", "POST"})
     */
    public function newAction(Request $request)
    {
        $post = new Post();
        $formHandler = $this->get('appbundle.post_form_handler');

        if ($formHandler->processForm($post)) {
            return $this->redirectToRoute('post_show', array('id' => $post->getId()));
        }

        return $this->render('post/new.html.twig', array(
            'post' => $post,
            'form' => $formHandler->getForm()->createView(),
        ));
    }

    /**
     * Finds and displays a post entity.
     *
     * @Route("/{id}", name="post_show")
     * @Method("GET")
     */
    public function showAction(Post $post)
    {
        $formHandler = $this->get('appbundle.post_form_handler');
        return $this->render('post/show.html.twig', array(
            'post' => $post,
            'delete_form' => $formHandler->createDeleteForm($post)->createView(),
        ));
    }

    /**
     * Displays a form to edit an existing post entity.
     *
     * @Route("/{id}/edit", name="post_edit")
     * @Method({"GET", "POST"})
     */
    public function editAction(Request $request, Post $post)
    {
        $formHandler = $this->get('appbundle.post_form_handler');
        if ($formHandler->processForm($post)) {
            return $this->redirectToRoute('post_edit', array('id' => $post->getId()));
        }

        return $this->render('post/edit.html.twig', array(
            'post' => $post,
            'edit_form' => $formHandler->getForm()->createView(),
            'delete_form' => $formHandler->createDeleteForm($post)->createView(),
        ));
    }

    /**
     * Deletes a post entity.
     *
     * @Route("/{id}", name="post_delete")
     * @Method("DELETE")
     */
    public function deleteAction(Request $request, Post $post)
    {
        $formHandler = $this->get('appbundle.post_form_handler');
        if ($formHandler->processDeleteForm($post)) {
            // $this->get('session')->getFlashBag()->add('Deleted Successfully');
        }

        return $this->redirectToRoute('post_index');
    }