Nami CMS - CORE Bundle

Installs: 11

Dependents: 1

Suggesters: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0


dev-master / 0.1.x-dev 2016-06-03 17:02 UTC


Welcome to the NamiCoreBundle repository - a Symfony 2.7 bundle.

Nami Logo

PhpInk\Nami\CoreBundle is the main bundle of a Nami CMS application. It contains the dependencies configuration, Doctrine ORM/ODM mapping and FOSRest controllers to provide an API.

  1. Installation

Getting started

Run the following command to install the bundle :

composer require phpink/nami-core-bundle

To get NAMI working with MongoDB, after specifying the configuration driver to ''odm''' instead of '''orm''', add the following line to your composer.json :

        "doctrine/mongodb-odm-bundle": "3.0.*@dev",

Then, add the following line to your AppKernel.php :

        new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),

Generate new RSA keys [optional]

Run the following OpenSSL commands to generate RSA keys for JSON Web Token authentication :

openssl genrsa -out app/var/jwt/private.pem -aes256 4096
openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pem
  1. API endpoints

All available endpoints are available in a Postman dump


Some http client you can run to test the API :

GET     http://host/api-doc/     REST API documentation [HTML]
GET     http://host/api/         REST API ping [JSON]
POST    http://host/api/token    API token getter [JSON]
GET     http://host/api/pages    API get all method [JSON]
GET     http://host/api/pages/1  API get one method [JSON]
POST    http://host/api/pages/1  API update one method [JSON]
DELETE  http://host/api/pages/1  API delete one method [JSON]

What's inside?

The bundle is configured with the following defaults:

  • Twig is the only configured template engine;

  • Translations are activated

  • Doctrine ORM/DBAL or Doctrine MongoDB is configured;

  • Swiftmailer is configured;

  • Annotations for everything are enabled.

It comes pre-configured with the following bundles:


API inner working


CoreBundle controllers extend a base AbstractController, which contains a set of methods for the Doctrine CRUD worflow. Associated Doctrine model/repository & FormType class names are guessed automatically.

For example: NamiCoreBundle:Model\Orm\User entity & NamiCoreBundle:Form\UserType for NamiCoreBundle:Controller\UserController.

The doctrine repository used by the controller to run the generic CRUD commands is the one associated by default to the model. A different one can be called :

public function getEntitiesAction() {
    $productRepo = $this->getRepository('Product'); // From model name
    // or
    $productRepo = $this->getRepository('\PhpInk\Nami\CoreBundle\Model\Orm\Products'); // More specific
    return $this->restView(...); // Returns a JSON response


Core repositories extend a base AbstractRepository, which contains all the CRUD methods called from controllers. Repositories can overload the base properties, such as orderByFields, filterByFields.

They must implement a buildItemsQuery method that will be called to create the Doctrine QueryBuilder retrieving one or more item from the database.

As for creation & update, the controllers instantiate the form type related to the associated model.

Json TO Forms

A JsonDecoder is implemented and modifies the input request data. It is called from the FosRest body listener (configuration is in src/PhpInk/CoreBundle/DependencyInjection/NamiCoreBundleExtension.php).

It transforms json input booleans true,false into optional 0,1 checkboxes for FormTypes.

To execute specific code after an item creation or update, take a look at the UserController::onPostSave method that sends the user confirmation mail.