こんにちは、Zend Framwork 2 の ZfcUser モジュールを使用してユーザー登録フォームを作成しようとしています。ユーザー フィールドを追加する際のベスト プラクティスについてアドバイスをお願いします。
これまでのところ、「WbxUser」という独自のモジュールを作成し、モジュールの wiki ページで説明さ れているように、モジュールのブートストラップ関数でイベント マネージャーを使用して、「userlastname」というカスタム フィールドを ZfcUser の登録フォームに追加しました。
コード:
//WbxUser.Module.php
namespace WbxUser;
use Zend\Mvc\MvcEvent;
class Module {
public function onBootstrap(MvcEvent $e){
$events = $e->getApplication()->getEventManager()->getSharedManager();
$events->attach('ZfcUser\Form\Register','init', function($e) {
$form = $e->getTarget();
$form->add(array(
'name' => 'userlastname',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Last Name',
),
));
// Do what you please with the form instance ($form)
});
$events->attach('ZfcUser\Form\RegisterFilter','init', function($e) {
$filter = $e->getTarget();
$filter->add(array(
'name' => 'userlastname',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'min' => 3,
'max' => 255,
),
),
),
));
});
}
public function getConfig(){
return array();
}
public function getAutoloaderConfig(){
return array();
}
}
しかし、この後、新しいフィールドが収集している余分なデータを保存するためのコードをどこに/どのように記述するかについて少し迷っています。
これは、追加フィールドの保存ルーチンを起動できるイベントですかhttps://github.com/ZF-Commons/ZfcUser/wiki/How-to-perform-a-custom-action-when-a-new-user -アカウントが作成されました
ZfcUser\Entity\User.php を拡張して新しいフィールドを追加する独自の WbxUser モデルを作成する必要がありますか?
私は ZF と MVC の初心者なので、書き込み方向のナッジには非常に満足しています。