I will explain how to setup a Zend Framework Application from the skeleton app in github and then how to install and configure the module called ZfcUser .
The purpose of ZfcUser is:
The purpose of ZfcUser is to provide a flexible foundation for the common practice of user authentication / identification and registration. Ultimately, a user will authenticate via some authentication adapter, and upon successful authentication will be identified by a populated user model for the given session. The focus of ZfcUser is flexibility and more importantly, extendibility. ZfcUser should be able to successfully serve as a starting point for authentication in a very large percentage of ZF2 web applications with widely varying names.
So lets start...
Requirements for this howto:
- PHP 5.3.3+ (with pdo-sqlite or pdo-mysql),
- I'm using php 5.4 that has a built in webserver (note: use it only for dev purposes!!!).
Install Zend Framework 2 ApplicationThe process is described here, but basically you install composer:
~> curl -s https://getcomposer.org/installer | php --
Then install the application using composer:
~> php composer.phar create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application
There are alternate methods in the skeleton application github page.
At this point we will have ZF2 MVC application installed and working, can check this using the php built in webserver (5.4+),
~>php -S localhost:8888 -t public/
and browsing to http://localhost:8888 with your browser:
Install ZfcUserEdit the composer.json file and add this line to require ZfcUser. Composer will automatically install ZfcBase thats a dependency of ZfcUser.
composer.json should look like this:
"description": "Skeleton Application for ZF2",
Then update the dependencies:
~> php composer.phar update
Configure Zend Framework to work with ZfcUserAdd those modules (ZfcBase and ZfcUser) to the application configuration so they can be bootstraped and configured, editing /config/application.config.php:
As you can see in your browser the module is active, browse http://localhost:8888/user
Let's setup the database with the schema that comes with ZfcUser. You can locate the folder /vendor/zf-commons/zfc-user/data . ZfcUser provides 3 schemas, one for postgres, one for mysql and one for sqlite. We will use sqlite configuration: schema.sqlite.sql .
From the root folder of the application, run:
~> cat vendor/zf-commons/zfc-user/data/schema.sqlite.sql | sqlite3 data/users.db
Now we need to configure the database adapter so the module can recognize it.
Create a file called database.local.php in the /config/autoload folder and add the configuration:
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'db' => array(
'driver' => 'pdo',
'dsn' => 'sqlite:'.getcwd().'/data/users.db',
And bam! its done, i can signup:
Check the wiki to override the default behavior: