2014-04-21 1 views
1

ZfcUser를 사용하여 사용자를 등록하고 하나의 형식으로 데이터베이스에 모델을 추가하려고합니다.ZF2 ZfcUser Service User :: register 메서드를 사용하여 다른 컨트롤러에서 사용자 등록을 시도하는 중 오류가 발생했습니다.

   'Application\Form\AuthorForm'  => function($sm) { 
        $options = $sm->get('zfcuser_module_options'); 
        $form = new AuthorForm('authorForm', $options); 
        return $form; 
       }, 

내가 : 나는 공장에서 다음 코드를 추가 Module.php에서

namespace Application\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\Form; 
use Zend\View\Model\ViewModel; 

use Application\Model\Author; 
use Application\Form\AuthorForm; 
use Application\Form\Author2Form; 

use ZfcUser\Service\User as UserService; 

class AdminController extends AbstractActionController { 
    protected $authorTable; 
    protected $registerForm; 
    protected $userService; 

    public function authorAction() { 
     $author = new Author(); 
     $form = $this->getRegisterForm(); 
     $formRegister = $this->getServiceLocator()->get('zfcuser_register_form'); 

     $formAuthor = new Author2Form(); 
     $request = $this->getRequest(); 
     $service = $this->getUserService(); 

     if ($request->isPost()) { 
      $post = $request->getPost(); 
      $post['email'] = $post['mail']; 
      $request->setPost($post); 

      $formAuthor->setValidationGroup(array('name', 'last_name', 'mail', 'group_name', 'description')); 
      $formRegister->setValidationGroup(array('email', 'password', 'passwordVerify')); 
      $form->setData($request->getPost()); 
      $formAuthor->setData($request->getPost()); 
      $formRegister->setData($request->getPost()); 

      if ($formAuthor->isValid() && $formRegister->isValid()) { 
       $service->register($formRegister->getData()); 
       $author->exchangeArray($formAuthor->getData()); 
       $this->getAuthorTable()->saveAuthor($author); 

       return $this->redirect()->refresh(); 
      } 
     } 

     return new ViewModel(array(
      'authorList' => $this->getAuthorTable()->fetchAll(), 
      'authorForm' => $form, 
     )); 
    } 

    public function getRegisterForm() { 
     if (!$this->registerForm) { 
      $this->setRegisterForm($this->getServiceLocator()->get('Application\Form\AuthorForm')); 
     } 
     return $this->registerForm; 
    } 

    public function setRegisterForm(AuthorForm $registerForm) { 
     $this->registerForm = $registerForm; 
    } 

    public function getUserService() { 
     if (!$this->userService) { 
      $this->userService = new UserService(); 
     } 
     return $this->userService; 
    } 

    public function setUserService(UserService $userService) { 
     $this->userService = $userService; 
     return $this; 
    } 

} 

: 그래서 나는 등록 양식을 확장하고이 같은 다른 형태로 POSTDATA을 제공함으로써 데이터의 유효성을 검사 두 형태의 유효성을 검사 할 수 후 다음과 같은 오류 메시지가 나타납니다

: 다음과 같은 방법이 될 것입니다

Fatal error: Call to a member function get() on a non-object in /var/www/*/vendor/zf-commons/zfc-user/src/ZfcUser/Service/User.php on line 241

아무도 나를 도와 주실 래요 ..

public function getOptions() { 
    if (!$this->options instanceof UserServiceOptionsInterface) { 
     $this->setOptions($this->getServiceManager()->get('zfcuser_module_options')); 
    } 
    return $this->options; 
} 

나는 그것을 달성하기 위해 이미 많은 것들을 시도하고 난 그냥 더 이상 시도하는 것을 잘 모릅니다?

답변

-2

이봐 당신의 컨트롤러에 넣고 :

$service->setServiceManager($this->getServiceLocator()); 
관련 문제