ZF-Commons / ZfcUser

A generic user registration and authentication module for ZF2. Supports Zend\Db and Doctrine2. (Formerly EdpUser)
BSD 3-Clause "New" or "Revised" License
497 stars 343 forks source link

How to change tablename 'user' to something else? #155

Closed back-2-95 closed 11 years ago

back-2-95 commented 11 years ago

I cannot find tablename setting on config?

br, Marko

atukai commented 11 years ago

Look at ZfcUser\Mapper\User.

back-2-95 commented 11 years ago

Yes I looked at it, but how to change name of the database? I wouldn't want to create new module just to overwrite that mapper...

atukai commented 11 years ago

As I understand, new module is only one way to overwrite smth. And later you might want to overwrite not only table name. ZfcUser provides only generic functionality.

ghost commented 11 years ago

You need to edit the $tableName on around line 11.

back-2-95 commented 11 years ago

I found that, but I'd prefer configuration. =)

Laustralien commented 11 years ago

I think you find a solution but you have to make a custom user mapper : in the Module.php of YOUR module pu that in the factories :

'zfcuser_user_mapper' => function ($sm) {
                                    $options = $sm->get('zfcuser_module_options');
                                    $mapper = new \MyCollaborateurs\Mapper\Collaborateurs() ;
                                    $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
                                    $entityClass = $options->getUserEntityClass();
                                    $mapper->setEntityPrototype(new $entityClass);
                                    $mapper->setHydrator(new \MyCollaborateurs\Mapper\MyCollaborateursHydrator());
                                    return $mapper;
                            },

And create the file Collaborateurs into the correct directory here : src/MyCollaborateus\mapper\ This file have to extends \ZfcUser\Mapper\User and know add the property :

   
protected $tableName  = 'collaborateur';
EvanDotPro commented 11 years ago

As mentioned, simply extend the User mapper and change the $tableName property... It should only take a couple of seconds. I'm not sure if setting all these in configuration is really worth it. That said, if the PR was done and no one was opposed to it, we could look at getting it merged.

rkarimhira commented 10 years ago

How to change table name 'user' to something else? In \ZfcUser\Mapper\User

protected $tableName = 'test';

but it's display an error message Please anyone help me with explanation I am beginner in ZF

sandeepsrivastava commented 10 years ago

When i change table name from "user" to something else. It doesn't reflact query with new table name and still seems with old table name. Please let me know the right way to change table name.

Danielss89 commented 10 years ago

As EvanDotPro states: "As mentioned, simply extend the User mapper and change the $tableName property... It should only take a couple of seconds. I'm not sure if setting all these in configuration is really worth it. That said, if the PR was done and no one was opposed to it, we could look at getting it merged."

sandeepsrivastava commented 10 years ago

Hi Danielss89, Thanks for your quite reply. I've already replaced the vaiable's "$tableName" value with my new table name, but didn't get any luck and result was same. After few hours research I found solution. There is a file named "ZfcUserDoctrineORM.Entity.User.dcm.xml" in which table name is manualy define. Below is the code of that file : <?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="ZfcUserDoctrineORM\Entity\User" table="user">

</entity>

After making changes in this file,I got the correct result.

Danielss89 commented 10 years ago

Yes, thats another case, Then your question should be in that repository and not this :)

kvfi commented 9 years ago

Actually, you don't even need a mapper, just modify:

ZfcUser/Options/ModuleOptions.php [103]

protected $tableName = 'users';
Danielss89 commented 9 years ago

@kouafi It's very bad practice to modify core files.