自定义类不能实例化!恶心有关问题送分!(用zend studio新建zendframework)

WBOY
Release: 2016-06-13 13:13:19
Original
811 people have browsed it

自定义类不能实例化!!!恶心问题送分!!(用zend studio新建zendframework)


models下denglu.php代码:
class denglu{
protected $_username;
protected $_password;
public function denglu(){

}
public function iddeng(){
if (($this->_username=='mr')&&($this->_password=='pass')) {
return true;
}else {
return false;
}
}
}

controllers下SelfController.php代码:

class SelfController extends Zend_Controller_Action{
public function init()
{
/* Initialize action controller here */
}
public function selfAction(){

}
//my页面
public function myAction(){
$this->view->assign("title","网页登录界面");
$this->view->assign("test","网页界面");
if ($this->_request->isPost()){
$username = $this->_request->getPost('username');
$password = $this->_request->getPost('password');
$dengl=new denglu(); //不能实例化!!!!!!!!
}
}
}

烦了我几天!!!!烦死人啦!!!!!!!!!!!!

------解决方案--------------------
我来给你解决吧!有两种方法:
第一种:修改你的入口文件index.php,如下:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../library/models'),
get_include_path(),
)));
/*-------------包含zend自动加载类*/
require_once "Zend/Loader/Autoloader.php";
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

第二种:在你的/application/下有一个Bootstrap.php文件,在此文件中添加如下代码:
/**
* 自动加载类
*/
protected function _initAutoLoad()
{
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
'namespace' => '',
'basePath' => APPLICATION_PATH
)
);
return $moduleLoader;
}

然后把models文件夹里面的类命名为Model_Denglu,文件名最好为Denglu.php(首字母大写)
实例化的时候这样用$dengl=new Model_Denglu(); 
以上两种方法都可以搞定。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template