Search code examples
mongodbzend-framework2

mongodb with zf2 gives an error The class was not found in the chain configured namespaces


I know I miss something in the configuration. Can anyone provide the steps for this configuration Mongo is running in my terminal properly. when connect with zend in sequential way it works . but in procedural way it gives error. this is global config file

'driver' => array(
        'odm_default' => array(
            'class'   => 'Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain',
            'drivers' => array()
        )
    ),

when I write

$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');

    $user = new User();
    $user->setName("Gembul");

    $dm->persist($user);

persist then it gives class not found error


Solution

  • When I found this error then I modify my database class means that change the comments in my model class in document section .

    use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
    /**
     * Description of User
     *
     * @author kiwitech
     */
    /** @ODM\Document(collection="user") */
    class Users 
    {
    
    protected $dm;
    /** @ODM\Id */
     private $_id;
    
    /** @ODM\Field(type="string") */
     private $_first_name;
    /** @ODM\Field(type="string") */
      private $_last_name;
    /** @ODM\Field(type="string") */
      private $_login_name;
    /** @ODM\Field(type="string") */
    private $_email;
    /** @ODM\Field(type="string") */
    private $tp_id;
    /** @ODM\Field(type="string") */
     private $_is_active;
    /** @ODM\Field(type="string") */
    private $_role_id;
    
    function get_id() {
        return $this->_id;
    }
    
    function get_first_name() {
        return $this->_first_name;
    }
    
    function get_last_name() {
        return $this->_last_name;
    }
    
    function get_login_name() {
        return $this->_login_name;
    }
    
    function get_email() {
        return $this->_email;
    }
    
    function getTp_id() {
        return $this->tp_id;
    }
    
    function get_is_active() {
        return $this->_is_active;
    }
    
    function get_role_id() {
        return $this->_role_id;
    }
    
    function set_id($_id) {
        $this->_id = $_id;
    }
    
    function set_first_name($_first_name) {
        $this->_first_name = $_first_name;
    }
    
    function set_last_name($_last_name) {
        $this->_last_name = $_last_name;
    }
    
    function set_login_name($_login_name) {
        $this->_login_name = $_login_name;
    }
    
    function set_email($_email) {
        $this->_email = $_email;
    }
    
    function setTp_id($tp_id) {
        $this->tp_id = $tp_id;
    }
    
    function set_is_active($_is_active) {
        $this->_is_active = $_is_active;
    }
    
    function set_role_id($_role_id) {
        $this->_role_id = $_role_id;
    }
    
    }
    

    then I easily solve this bug :)