The*_*lis 6 php model-view-controller zend-framework2
您好我正在尝试使用ZfcUser模块为Zend Framwork 2编写用户注册表单,并希望在添加更多用户字段时获得有关最佳做法的一些建议.
到目前为止,我已经创建了自己的模块"WbxUser",并且在模块维基页面中概述了 我在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();
}
}
Run Code Online (Sandbox Code Playgroud)
但在此之后,我在编写代码的位置/方法上有点迷失,以保存我的新字段正在收集的额外数据.
这是我可以为其他字段启动保存例程的事件https://github.com/ZF-Commons/ZfcUser/wiki/How-to-perform-a-custom-action-when-a-new-user -account-是创建
我应该编写自己的WbxUser模型,扩展ZfcUser\Entity\User.php以添加我的新字段
我有点像ZF和MVC菜鸟,因此在写入方向上轻推是非常好的.