新手求解: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。
求高手解答!!!!
回复讨论(解决方案)
你的这种写法似乎不合他的规矩吧?不过我也没有用过这个玩意
你在 $model = new $className; 前加一句
include_once $classPath;
看看
呵呵 我是外行 zf 好像 有一个工具 可以方便创建 控制器 模型 试图 安装好后 直接在cmd下面 zf create xxxx 就能自己创建
这个类的头文件引用了没?
这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用
引用 3 楼 nirvana_newbie 的回复:这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用
就在你写这些代码的PHP文件中的开头引用一下。include_once 'CreditYd.php';
引用 4 楼 yeinuse 的回复:引用 3 楼 nirvana_newbie 的回复:这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用
就在你写这些代码的PHP文件中的开头引用一下。include_once 'CreditYd.php';
但是现有的model中的源代码好像也没看到被引用,还是要某个地方被引用了?
引用 5 楼 nirvana_newbie 的回复:引用 4 楼 yeinuse 的回复:引用 3 楼 nirvana_newbie 的回复:这个类的头文件引用了没?
类的头文件是???只有CreditYd.php, 在哪里引用
就在你写这些代码的PHP文件中的开头引用一下。include_once 'CreditYd.php';
但是现有的model中的源代码好像……
一般开源的框架都是封装好的,所有的头文件及常用函数都写到一个文件中,比如include 'utils.php'在这个utils.php中引入了许多头文件,那么到你的页面中只需要引入utils.php就可以了。所以说你看不到其他文件引用你这个model的头文件。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
