こんにちは、私はZend Framwork 2のZfcUserモジュールを使用してユーザー登録フォームを作成しようとしています。Zend Framework 2でZfcUserを拡張する
これまでのところ私は自分のモジュール「WbxUser」を作成しました。modules wiki pagesで説明したように、私のモジュールブートストラップ機能でイベントマネージャを使ってZfcUserの登録フォームに「userlastname」というカスタムフィールドを追加しました。
コード:
//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();
}
}
しかし、この後、私は/私の新しいフィールドが収集され、余分なデータを保存するためのコードを書く方法どこで失われたビットを持っています。
- は、この私の新しいフィールドを追加するZfcUser \エンティティ\ User.phpを拡張し、私は私自身のWbxUserモデルを書くことなら、私は追加のフィールド
https://github.com/ZF-Commons/ZfcUser/wiki/How-to-perform-a-custom-action-when-a-new-user-account-is-createdするためのルーチンのセーブオフ発射できるイベントです
私は少しZFとMVCのnoobですので、書き込み方向の微妙な変化には非常に大きなものになります。時には、それは多くの機能を不安定にするので
この投稿を見ることができます:http://stackoverflow.com/questions/8783873/zf2-whats-the-best-practice-for-working-with-vendor-modules-form-classes – nXqd
恐ろしいそれは助けになる。私はモジュールを書く際に亀裂があり、私のために働いていたものを投稿します。再度、感謝します。 –
ありがとう、私はあなたを見て楽しみにしています。私は同じことに取り組んでいます:) – nXqd