使用Zend Framework中的模块加载模型时遇到问题

时间:2010-09-01 16:04:48

标签: php zend-framework zend-db-table

我有一个像this这样的文件夹结构,我正在尝试在我的控制器中加载News模型:

<?php
/**
 * Login
 */
class Admin_NewsController extends Zend_Controller_Action {

    public function preDispatch() {
        $layout = Zend_Layout::getMvcInstance();
        $layout->setLayout('admin');
    }
    public function init() {
        $this->db = new Application_Admin_Model_DbTable_News();
    }

    public function indexAction() {

    }

    public function addAction() {
        //$this->getHelper('viewRenderer')->setNoRender();
        // Calls the Request object
        $request = $this->getRequest();

        if ($request->isPost()) {
            // Retrieves form data
            $data = array(
                "new_title" => $request->getParam('txtTitle'),
                "new_text" => htmlentities($request->getParam('txtNews')),
                "new_image" => $request->getParam('upName'),
                "new_published" => 1
            );
            // Inserts in the database
            if ($this->db->addNews($data)) {
                $this->view->output = 1;
            } else {
                $this->view->output = 0;
            }
        } else {
            $this->view->output = 0;
        }

        $this->_helper->layout->disableLayout();
    }
}

我的模型

<?php

class Application_Admin_Model_DbTable_News extends Zend_Db_Table_Abstract
{
    protected $_name = 'news';

    public function addNews($data) {
        $this->insert($data);
    }
}

Althoug我收到此错误: alt text

1 个答案:

答案 0 :(得分:1)

由于您的新闻类属于该模块,因此其名称应为Admin_Model_DbTable_News,不带Application_前缀。

http://framework.zend.com/manual/en/zend.loader.autoloader-resource.html#zend.loader.autoloader-resource.module

的模块中查看有关自动加载的详情