[TYPO3-mvc] Extending fe_users

Jochen Rau jochen.rau at typoplanet.de
Tue Jan 12 23:06:47 CET 2010


Hi Manuel.

On 12.01.10 19:54, Manuel Simon wrote:
> I'm currently trying to implement a extension with extbase and fluid and
> I'm stuck extending the fe_users table.
> While I can edit all available fields in the BE and access the normal
> fe_users fields from extbase, I'm not able to access the extra fields.
>
> Below you can find my current work.
>
> I thought about doing a select in a __construct section in the Model,
> but after reviewing some slides I guess, this would be the wrong place.

Yes.

> In ext_tables.php:
> ---
> $AdditionalFeUsersColumns = Array (
> 	"tx_..._..Nr" =>  Array (
> 			"exclude" =>  0,
> 			"label" =>  "Nummer",
> 			"config" =>  Array (
> 				"type" =>  "input",
> 				"size" =>  "30",
> 				"max" =>  "6",
> 				"eval" =>  "required,trim",
> 				)
> 		),
> 	
> );
>
> t3lib_div::loadTCA("fe_users");
> t3lib_extMgm::addTCAcolumns("fe_users", $AdditionalFeUsersColumns, 1);
> t3lib_extMgm::addToAllTCAtypes("fe_users","tx_..._...Nr");
> ---

Seems ok to me. I assume that you have prefixed your column name 
("tx_..._..Nr" is something like "tx_myext_telephoneNr"). I suggest to 
use "tx_myext_telephone_nr" instead to be consistent (lowerCameCase in 
the Model, lower_underscore in the database).

> In ext_tables.sql:
> ---
> CREATE TABLE fe_users (
> 	tx_..._...Nr char(6) DEFAULT '' NOT NULL,
> );
> ---

Ok.

> Model
> ---
> class Tx_..._Domain_Model_Participant extends
> Tx_Extbase_Domain_Model_FrontendUser {
>
> 	/**
> 	 * tx_..._...Nr
> 	 * @var string
> 	 */
> 	 protected $tx_..._...Nr;

Let's assume "tx_..._..Nr" is "tx_myext_telephoneNr". In this case 
"tx_myext_telephoneNr" is a bad choice for a property name. It should be 
written in lowerCamelCase and without a prefix (as this is not related 
to your domain but a technical solution in the database).


> Repository
> ---
> class Tx_..._Domain_Repository_ParticipantRepository extends
> Tx_Extbase_Domain_Repository_FrontendUserRepository {
> }
> ---

Ok. Not much code to make mistakes ;-)

> Controller
> ---
> 	public function listAction() {
> 		$this->participantRepository =
> t3lib_div::makeInstance('Tx_..._Domain_Repository_ParticipantRepository');
> 		$this->participant =
> t3lib_div::makeInstance('Tx_..._Domain_Model_Participant');

You don't have to instanciate a Tx_..._Domain_Model_Participant here.

> {
> 			if($this->participant =
> $this->participantRepository->findOneByUid(intval($GLOBALS['TSFE']->fe_user->user['uid'])))
> 			{			
> 				$this->view->assign('...nr', $this->participant->get...Nr());
> 				$this->view->assign('zip', $this->participant->getZip());
> 			}
> 		}
> 		
> 	}
> ---

Ok (by reading).

> I also tried extending tca.php
> ---
> $TCA['tx_..._domain_model_participant'] = array(
> 	'ctrl' =>  $TCA['tx_..._domain_model_participant']['ctrl'],
> 	'interface' =>  array(
> 		'showRecordFieldList' =>  'tx_..._...Nr'
> 	),
> 	'types' =>  array(
> 		'1' =>  array('showitem' =>  'tx_..._...Nr')
> 	),
> 	'palettes' =>  array(
> 		'1' =>  array('showitem' =>  '')
> 	),	
> 	'columns' =>  array(
> 		'tx_..._...Nr' =>  array(
> 			'exclude' =>  0,
> 			'config' =>  array(
> 				"type" =>  "input",
> 				"size" =>  "30",
> 				"max" =>  "6",
> 				"eval" =>  "required,trim",
> 				"foreign_table" =>  "fe_users",
> 			),
> 		),
> 	),
> );
> ---

Not necessary.

There is something missing. You have to map your database table onto 
your domain model.

config.tx_extbase {
	persistence{
		classes {
			Tx_Extbase_Domain_Model_FrontendUser {
				mapping {
					columns {
tx_myext_telephoneNr.mapOnProperty = telephoneNr
					}
				}
			}
		}
	}
}

Maybe solves the problem.

Jochen


More information about the TYPO3-project-typo3v4mvc mailing list