使用Zend Framework 2扩展ZfcUser [英] Extending ZfcUser with Zend Framework 2

查看:59
本文介绍了使用Zend Framework 2扩展ZfcUser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用Zend Framwork 2的ZfcUser模块编写用户注册表格,并希望在添加更多用户字段时获得一些最佳做法方面的建议.

Hi I am trying to write a user registration form using ZfcUser module for Zend Framwork 2 and would like some advice on best practices when adding more user fields.

到目前为止,我已经创建了自己的模块"WbxUser",如

So far I have created my own module called "WbxUser" and as outlined in the modules wiki pages I have added a custom field called "userlastname" to ZfcUser's registration form by using the Event Manager in my modules bootstrap function like so.

代码:

//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();
    }
}

但是在此之后,我对在哪里/如何编写代码以保存新字段正在收集的额外数据方面有些迷惑.

But after this I have got a bit lost on where/how to write the code to save the extra data that my new fields are gathering.

  1. 这是我可以针对其他字段触发保存例程的事件吗 https://github.com/ZF-Commons/ZfcUser/wiki/How-to-perform-a-custom-action-when-a -创建了新用户帐户

我应该编写自己的WbxUser模型来扩展ZfcUser \ Entity \ User.php来添加新字段

Should I be writing my own WbxUser model that extends ZfcUser\Entity\User.php to add my new fields

我是ZF和MVC的新手,因此对于写方向上的微调而言非常适合.

I am a bit of a ZF and MVC noob so would be very great-full for a nudge in the write direction.

推荐答案

这似乎更直观

http://juriansluiman. nl/zh-CN/article/117/use-3rd-party-modules-in-zend-framework-2

这篇关于使用Zend Framework 2扩展ZfcUser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆