Newbie solving: questions about how to create a new Class in the Zend Framework

Source: Internet
Author: User
Tags php website
Newbie's solution: Under the Zend Framework, how to create a new Class has recently helped a friend company change the background of a PHP website. I have never done it before. The website structure is roughly as follows: --------------------------------------------------/applica: how to create a new Class under the Zend Framework
I recently helped my friend company change the background of a PHP website. I have never done it before.
The website structure is roughly as follows:
--------------------------------------------
/Application/
./Admin/controllers/
./Admin/views/
/Library/
./App/
./App/Db. php
./App/Model. php
./App/Db/
./App/Model/

./Zend/
/Wwwroot/
...
--------------------------------------------
The/library/App/Model/directory stores the php file of the existing CLASS object, so I created a new file CreditYd. php based on the same principle and created a new CLASS:
Class App_Model_CreditYd extends App_Model_Abstract
{
Omitted functions
}
However, an error occurred while calling App_Model: factory ('credityd'); in controllers. The functory function is as follows:
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 ');
}
}
}
}
--------------------
The error line is in $ model = new $ className;. why cannot the object be found ??
Because Zend has never been used, and you do not know how to create objects. do you want to include objects like C? make is required.
Please answer !!!! Framework Zend PHP
------ Solution --------------------
Does your writing seem to be against his rules? But I have never used this.

Add a sentence before $ model = new $ className;
Include_once $ classPath;
Look


------ Solution --------------------
Haha, I am a layman. zf seems to have a tool that allows you to easily create a controller model. after trying to install the controller model, you can directly create your own one in zf create xxxx under cmd.
------ Solution --------------------
Is the header file of this class referenced?
------ Solution --------------------
Reference:
Reference: is the header file of this class referenced?
Class header file is ??? Only CreditYd. php, where to reference

Reference it at the beginning of the PHP file where you write the code. Include_once 'credityd. php ';
------ Solution --------------------
Reference:
Reference: reference: is the header file of this class referenced?
Class header file is ??? Only CreditYd. php, where to reference
Reference it at the beginning of the PHP file where you write the code. Include_once 'credityd. php ';
But the source code in the existing model seems to be ......

Generally, open-source frameworks are encapsulated. all header files and common functions are written into a file, such as include 'utils. php' in this utils. php introduces many header files, so you only need to introduce utils to your page. php. Therefore, you cannot see other files to reference the header file of your model.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.