Note you will need a User Bundle so that you can map the ProfileUserInterface to your own User entity. You can use whatever User Bundle you prefer. FOSUserBundle is highly rated.
Installation takes only 5 steps:
- Download and install dependencies via Composer.
- Register bundles with AppKernel.php.
- Update your app/config/routing.yml.
- Update your app/config/config.yml.
- Update your user entity.
- Update your database schema.
Append the following to end of your applications composer.json file (found in the root of your Symfony2 installation):
// composer.json
{
// ...
"require": {
// ...
"codeconsortium/ccdn-user-profile-bundle": "dev-master"
}
}Then, you can install the new dependencies by running Composer's update
command from the directory where your composer.json file is located:
$ php composer.phar updateNow, Composer will automatically download all required files, and install them
for you. All that is left to do is to update your AppKernel.php file, and
register the new bundle:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new CCDNUser\ProfileBundle\CCDNUserProfileBundle(),
// ...
);
}Notice this include KNP Paginator, which is an important dependency.
In your app/config/routing.yml add:
CCDNUserProfileBundle:
resource: "@CCDNUserProfileBundle/Resources/config/routing.yml"
prefix: /In your app/config/config.yml add:
# app/config/config.yml
ccdn_user_profile:
entity:
user:
class: Acme\YourUserBundle\Entity\UserReplace Acme\YourUserBundle\Entity\User with the user class of your chosen user bundle.
In order for the bundle to function correctly, you need to implement the ProfileUserInterface. This interface extends
the Symfony user interface.
Your user entity would then look like similar to the following:
namespace My\Bundle\Entity;
use CCDNUser\ProfileBundle\Entity\ProfileUserInterface;
class MyUser implements ProfileUserInterface
{
/**
*
* @access protected
* @var \CCDNUser\ProfileBundle\Entity\Profile $profile
*/
protected $profile;
/**
*
* @access protected
* @var \DateTime $registeredDate
*/
protected $registeredDate;
public function __construct()
{
parent::__construct();
// your own logic
$this->registeredDate = new \Datetime('now');
}
public function setProfile(Profile $profile)
{
$this->profile = $profile;
}
public function getProfile()
{
return $this->profile;
}
/**
* Get registeredDate
*
* @return \Datetime
*/
public function getRegisteredDate()
{
return $this->registeredDate;
}
/**
* Set registeredDate
*
* @param \Datetime $registeredDate
*/
public function setRegisteredDate(\Datetime $registeredDate)
{
$this->registeredDate = $registeredDate;
}
// Symfony UserInterface required methods ...
}Make sure to add the ProfileBundle to doctrines mapping configuration:
# app/config/config.yml
# Doctrine Configuration
doctrine:
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
resolve_target_entities:
CCDNUser\ProfileBundle\Entity\ProfileUserInterface: Acme\YourUserBundle\Entity\User
entity_managers:
default:
mappings:
CCDNUserProfileBundle:
mapping: true
type: yml
dir: "Resources/config/doctrine"
alias: ~
prefix: CCDNUser\ProfileBundle\Entity
is_bundle: trueReplace Acme\YourUserBundle\Entity\User with the user class of your chosen user bundle.
From your projects root Symfony directory on the command line run:
$ php app/console doctrine:schema:update --dump-sqlTake the SQL that is output and update your database manually.
Warning:
Please take care when updating your database, check the output SQL before applying it.
If you have pre-existing users, you need to migrate them to attach a default profile. This bundle contains a task which does this for you. It can be run with:
$ php app/console ccdn-user-profile:migrate-usersIf you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config.
# app/config/config.yml
framework:
translator: ~Installation should now be complete!
If you need further help/support, have suggestions or want to contribute please join the community at Code Consortium