找不到“Shanty_Mongo_Document”类

时间:2012-09-19 15:02:41

标签: php zend-framework mongodb

尝试和Shanty Mongo一起玩,Zend(我是两个都是新手),但我一直在努力:

"Fatal error: Class 'Shanty_Mongo_Document' not found
    in /var/www/dbtz/application/models/User.php on line 4"

首先,我的控制器的indexAction:

public function indexAction()
{
    $this->view->pageTitle = "Add User";

    $form = new Application_Form_UserAdd();

    if ($this->_request->isPost()) {
        $formData = $this->_request->getPost();
        if ($form->isValid($formData)) {
            $user = new Application_Model_User();
            $user->username = $formData['username'];

            $user->save();
            exit;
        } else {
            $form->populate($formData);
        }
    }        

    $this->view->form = $form;
}

其次,模型:

class Application_Model_User extends Shanty_Mongo_Document
{
    protected static $_db = 'dbtz';
    protected static $_collection = 'user';

    public static $_requirements = array(
        'username' => 'Required',
        'password' => 'Required',
    );
}

我将库/ Shanty目录符号链接到库文件夹中。这就是我如何包含Zend库,它工作正常。

库文件夹的树:

/var/www/dbtz/library# tree -l
.
├── Shanty -> /var/www/libs/Shanty-Mongo/library/Shanty/
│   ├── Mongo
│   │   ├── Collection.php
│   │   ├── Connection
│   │   │   ├── Group.php
│   │   │   └── Stack.php
│   │   ├── Connection.php
│   │   ├── Document.php
│   │   ├── DocumentSet.php
│   │   ├── Exception.php
│   │   ├── Iterator
│   │   │   ├── Cursor.php
│   │   │   └── Default.php
│   │   └── Validate
│   │       ├── Array.php
│   │       ├── Class.php
│   │       └── StubTrue.php
│   ├── Mongo.php
│   └── Paginator
│       └── Adapter
│           └── Mongo.php
└── Zend -> /usr/share/php/libzend-framework-php/Zend/
...

1 个答案:

答案 0 :(得分:2)

想出来。需要添加

autoloaderNamespaces[] = "Shanty_"

到我的application.ini