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

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

Jun 13, 2016 pm 12:47 PM
app model nbsp php

新手求解: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的头文件。
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

See all articles