Heim  >  Artikel  >  Backend-Entwicklung  >  新手求解:Zend框架下,怎么创建新Class的有关问题

新手求解:Zend框架下,怎么创建新Class的有关问题

WBOY
WBOYOriginal
2016-06-13 12:47:54714Durchsuche

新手求解:Zend框架下,如何创建新Class的问题
近期在帮朋友公司改个PHP网站的后台,PHP我是半路上手,之前没弄过。
大致看了一下,网站的结构大致如下:
--------------------------------------------
/application/
           ./admin/controllers/
           ./admin/views/
/library/
       ./App/
       ./App/Db.php
       ./App/Model.php
       ./App/Db/
       ./App/Model/

       ./Zend/
/wwwroot/
...
--------------------------------------------
/library/App/Model/目录下存放的是现有的CLASS对象的PHP文件,那么我就安装相同的原理新建了一个新文件CreditYd.php,并创建一个新类:
class App_Model_CreditYd extends App_Model_Abstract
{
省略函数
}
但是在controllers中调用App_Model::factory('CreditYd');时出错。functory函数如下:
class App_Model
{
static public function factory($model)
{
$className = 'App_Model_' . $model;
$classPath = _LIB_DIR_ . '/App/Model/' . $model . '.php';

if (!file_exists($classPath)) {
throw new Exception('Class Not Fonud');
} else {

$model = new $className;

//error_log("[new className]\r\n", 3, _LIB_DIR_ . '/App/error.log');

if ($model instanceof App_Model_Abstract) {
return $model;
} else {
throw new Exception('Error');
}
}
}
}
--------------------
错误行是在 $model = new $className;,是找不到对象??
因为没有使用过Zend,也不知道如何创建对象,是不是要像C语言一样的,需要包含,需要make。
求高手解答!!!!

框架 Zend PHP
------解决方案--------------------
你的这种写法似乎不合他的规矩吧?不过我也没有用过这个玩意

你在 $model = new $className; 前加一句
include_once $classPath;
看看


------解决方案--------------------
呵呵 我是外行 zf 好像  有一个工具 可以方便创建 控制器 模型 试图  安装好后  直接在cmd下面  zf create xxxx  就能自己创建
------解决方案--------------------
这个类的头文件引用了没?
------解决方案--------------------
引用:
引用:这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用

就在你写这些代码的PHP文件中的开头引用一下。include_once 'CreditYd.php';
------解决方案--------------------
引用:
引用:引用:引用:这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用
就在你写这些代码的PHP文件中的开头引用一下。include_once 'CreditYd.php';
但是现有的model中的源代码好像……

一般开源的框架都是封装好的,所有的头文件及常用函数都写到一个文件中,比如include 'utils.php'在这个utils.php中引入了许多头文件,那么到你的页面中只需要引入utils.php就可以了。所以说你看不到其他文件引用你这个model的头文件。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn