您好,我正在尝试使用 Zend Framwork 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();
}
}
但在此之后,我对在哪里/如何编写代码来保存我的新字段收集的额外数据有点迷茫。
这是我可以为附加字段触发保存例程的事件吗 https://github.com/ZF-Commons/ZfcUser/wiki/How-to-perform-a-custom-action-when-a-new-user-account-is-created
我是否应该编写自己的 WbxUser 模型来扩展 ZfcUser\Entity\User.php 以添加我的新字段
我是 ZF 和 MVC 的新手,所以非常适合在写入方向上插入。
最佳答案
关于php - 使用 Zend Framework 2 扩展 ZfcUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630526/