无法在zend框架的控制器中加载模型

时间:2014-01-06 11:14:10

标签: php mysql zend-framework

尝试在控制器中加载模型时,我遇到了以下错误 致命错误:第27行的/var/www/html/ZendTecAdmin/application/controllers/AdminController.php中找不到“Admin_Model_Adminlogin”类

以下是控制器 AdminController.php

<?php

class AdminController extends Zend_Controller_Action {

    public function init() {

        $this->_helper->layout->setLayout('layout_admin');
        //$this->view->headScript()->appendFile($view->getBaseUrl.'js/jquery-1.10.2.min.js');
        //$this->view->headScript()->appendFile($view->getBaseUrl.'js/validate.js');
    }

    public function indexAction() {
        echo 'Welcome';
    }

    public function loginAction() {
        $mysession = new Zend_Session_Namespace('Admin');                
        $form = new Application_Form_loginForm();
        $this->view->form = $form;
    //Preform Admin login action
        if($this->_request->getPost('Login')){
            $formData=$this->_request->getPost();
            if($form->isValid($formData)){ //If form data is valid
                $name=$this->_request->getPost('username');
                $password=$this->_request->getPost('password');
                /****Creating object of model adminlogin class*****/
                               $adminLoginObj=new Admin_Model_Adminlogin();
                $fetchResult=$adminLoginObj->checkAdminAuthority($name,$password);
                if(count($fetchResult)>0){
                    $mysession->adminName=$name;
                    $this->_redirect('/admin/');
                }else{
                    $mysession->failLogin="Invalid Username or Password!";
                    $this->_redirect('/admin/login');

                }
            }
        }
    }

}

以下是Application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "quickstat"
resources.db.isDefaultTableAdapter = true
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.baseUrl = "/ZendTecAdmin/"

resources.session.remember_me_seconds = 864000

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1


resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug
includePaths.models = APPLICATION_PATH "/models/"

和模特 应用/模型/ admin.php的

<?php
    class Admin_Model_Adminlogin extends Zend_Db_Table{
        /* The Model Class Will be associated with register table*/

        protected $_name='users';

        function checkAdminAuthority($name,$pasword){
            $where="username='".$name."' and password='".$pasword."'";
            return $row=$this->fetchRow($where);
        }

    }

请帮我解决此问题。

4 个答案:

答案 0 :(得分:0)

如果您的模型是模型应用程序/ models / Admin.php 那么这个模型的类名应该是

 class Admin_Model_Admin

答案 1 :(得分:0)

你的模型扩展了Zend_Db_table它应该扩展Zend_Db_Table_Abstract

class Admin_Model_Adminlogin extends Zend_Db_Table_Abstract{

答案 2 :(得分:0)

请尝试使用以下代码创建模型对象:

$adminLoginObj = new Application_Model_Adminlogin();

答案 3 :(得分:0)

请更新文件名和类名,如下所示

文件名:AdminLogin.php

班级名称:Application_Model_Adminlogin

class Application_Model_Adminlogin extends Zend_Db_Table{

将对象创建为

$adminLoginObj = new Application_Model_Adminlogin(); 

我希望这会对你有所帮助。