paolo@bimodesign.com | +34 608 61 64 10

Framework

        

Zend2-Doctrine 2 and MongoDb (A Blog)

I'll start creating a simple blog using Zend 2, Doctrine 2 and MongoDB. In particulary in this first post you'll find a login and create users controllers adding the flashmessanger options to show the message return every time submitting form.
The blog is based on these previous Zend 2, Doctrine 2 and MongoDB installation and CRUD examples and you can clone or download the zip from my github account.

Installation and Configuration
CRUD - Insert/create document
CRUD - Select document
CRUD - Update/Delete document

and of course you can find all the methods and all the documentation at the Doctrine Oficial link
For this first part of the blog, I'll create the module "Login" and "User", and the first part of the "Post" controller that I'll explain in a future post.
The most important features in my code is the create a common layouts for all the modules. The main layout is called layout.phtml and these "partial" layouts flashmessage.phtml, footer.phtml, header.phtml, menu.phtml, modal.phtml. These latters are included from the layout.phtml.
The directory of the layout is on Application/view/layout/partials as you can see in the git repository.
And the other relevant features is to create a view helper (UserconnectData) to show the user session data after connection. It's the code:
Path: /HOME/module/Login/src/Login/View/Helper/UserconnectData.php

namespace Login\View\Helper;

use Zend\View\Helper\AbstractHelper;

class UserconnectData extends AbstractHelper {

    /**
     * __invoke
     *
     * @access public
     * @param  string
     * @return String
     */
    public function __invoke() {
        $userSession = new \Zend\Session\Container('user');
        $userName = $userSession->offsetGet('userData');

        return $userName->login;
    }
}

Adding this code to the module/Login/Module.php file is

    public function getViewHelperConfig()
    {
        return array(
            'factories' => array(
                'userconnectData' => function ($helperPluginManager) {
                    $viewHelper = new View\Helper\UserconnectData();

                    return $viewHelper;
                }
            ),
        );
    } 

Then I call it from the create.phtml Post view in this simple way

echo $this->userconnectData();

You can find all code in my github account, including the manage of MongoDB using Doctrine 2 and the error message using the flashmessage