1

尝试与 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',
    );
}

我将 library/Shanty 目录符号链接到 library 文件夹中。这就是我包含 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/
...
4

1 回答 1

2

弄清楚了。需要添加

autoloaderNamespaces[] = "Shanty_"

到我的 application.ini

于 2012-09-19T15:22:56.023 回答