Introduction, installation, and instance running of 2ZendFramework for PHP framework Learning

Source: Internet
Author: User
Tags autoloader
The framework aims to improve development efficiency, facilitate communication and collaboration between team developers, and improve the maintainability of applications. Learning to understand one or more frameworks will be helpful for practical projects. I. Introduction to ZendFramework: ZendFramework (ZF), with a Model-View-Controller (MVC) three-layer architecture

The framework aims to improve development efficiency, facilitate communication and collaboration between team developers, and improve the maintainability of applications. Learning to understand one or more frameworks will be helpful for practical projects. I. Introduction to ZendFramework: ZendFramework (ZF), with a Model-View-Controller (MVC) three-layer architecture

The framework aims to improve development efficiency, facilitate communication and collaboration between team developers, and improve the maintainability of applications. Learning to understand one or more frameworks will be helpful for practical projects.
1. Introduction to ZendFramework:
ZendFramework (ZF) is based on the Model-View-Controller (MVC) architecture. Separate different parts of the program, making it easier to develop programs without affecting each other and maintain them later.
ZF framework design ideas and strategies:
ZF adopts the Front-end Controller design mode, which sends all users' requests to a central control point. The specific method is that all requests must pass the index. php Portal (single portal can be implemented with Web servers, which will be mentioned later ). Then, the user requests are distributed to the corresponding controller through the script in index. php. The Controller is responsible for calling the logic (Model) and View presentation in the Model.

Ii. ZendFramework installation and simple instances
System Requirements: ZendFramework-1.9.3, CentOS 5.2 +
1. Download ZF (http://framework.zend.com/download/latest)
2. decompress and place the library class to the root directory of the project. For example,/var/www/nbaplayers/library/Zend ......
3. Create a basic project directory:


4. instance:
4.1 create a file/var/www/nbaplayers/index. php:
Error_reporting (E_ALL | E_STRICT); // The error output is enabled for code debugging. The officially released code should shield the error message.
Date_default_timezone_set ('Asia/Shanghai'); // set the time zone
Set_include_path ('.'.
PATH_SEPARATOR. './library './/This parameter is used to set the path of the class library. The ZF system class library is specified here.
PATH_SEPARATOR. 'application/models /'.// Contains the custom class file.
PATH_SEPARATOR. get_include_path ()
);
Require_once 'zend/Loader. php ';
Zend_Loader: registerAutoload ();//Automatic loading class

$ FrontController = Zend_Controller_Front: getInstance ();//Obtain the Zend_Controller_Front class instance
$ FrontController-> setControllerDirectory (array (
"Default" => 'application/controllers ',
); // Specifies the path of a group of controller files. The parameter is an array.Set the front-end controller to let the Controller know where our controller class is.
$ FrontController-> throwExceptions (true );//Let the front-end controller throw all exceptions.By default, the front-end controller will capture these exceptions and pass them to the ErrorController controller. during the development process, such errors are easy to detect. However, in actual operation, these errors cannot be directly displayed to the front-end users.
$ FrontController-> setParam ('noviewrenderer', true );//Specifies that the view is not used. false is the default value.
$ FrontController-> setParam ('noerrorhandler', false );
$ FrontController-> dispatch ();//Program Execution Distribution
?>
Note: If you use a previous ZF version, the following prompt appears:
Notice: Zend_Loader ::Zend_Loader: registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0;Use Zend_Loader_Autoloader instead in/usr/local/zend/share/ZendFramework/library/Zend/Loader. php on line 207
Then:
Require_once 'zend/Loader. php ';
Zend_Loader: registerAutoload (); // automatically loaded class
To:
Require_once 'zend/Loader/Autoloader. php'; // automatically load the class
$ Loader = Zend_Loader_Autoloader: getInstance ();
$ Loader-> setFallbackAutoloader (true );
$ Loader-> suppressNotFoundWarnings (false );
That's all. For details, refer to the official instructions of ZF. In the Autoloader. php file, there is a method:
Protected function _ construct ()
{
Spl_autoload_register (array (_ CLASS __, 'autoload '));
$ This-> _ internalAutoloader = array ($ this, '_ autoload ');
}
Used to automatically load class files.
* Spl_autoload_register-Register given function as _ autoload () implementation
// Set Automatic Object Loading


4.2 create a file/var/www/nbaplayers/application/Controllers/IndexController. php:
Class IndexController extends Zend_Controller_Action
{
Function indexAction ()
{
Echo "Hello ZendFramework! ";
}
}
?>

4.3 create a file/var/www/nbaplayers/. htaccess
RewriteEngine on
RewriteRule! /. (Js | ico | gif | jpg | png | css) $ index. php

In the preceding example, the RewriteEngine engine is started and the index. php file is used for all images, js scripts, css requests, gif, jpg, png, and css requests. Of course, the above instance can run normally without creating this, but if you use ZF to develop the actual project, this is required.

4.4 run: Enter the http://www.domain.com press enter in the browser address bar, the browser will display the result:
Hello ZendFramework!
OK!

Install and use the Aptana plug-in on Zend Studio (html, css, and js Code prompt functions)

I recently installed zend studio 9.0 and used it for a while to find that I didn't prompt to write html, css, and js Code. I wanted to open dreamwaver (not good for js Code ). I searched the internet and found the Aptana plug-in. It feels good to install it.

Post the official website: http://www.aptana.com/

1. installation steps:

1. zend studio-> Help-> Install New Software-> work with click add (SEE)


2. There are two options:

(1) Local (Local installation)

(2) Online installation, location input: http://download.aptana.org/tools/studio/plugin/install/studio

Someone said on the Internet that only online installation is successful, and I can use it just like local installation. ,


3. After installation, restart zend.

2. Configure the editor

1. Window? Preferences? General? Etitors? Fill Associations. Then, select the file format you want to edit with Aptana by Default on the right side, select the following Aptana plug-in, and set Default to Default.


2. Cancel the start page of Aptana

Then I found that every time I open zend, Aptana will display the start page. How can I cancel it?

SingleWindow? Preferences? Aptana? Strartup Page? Select Never display after startup


3. How to Use Aptana (SEE)

. Css or. js files


Okay. Let's see the effect.

CSS


JS

If you are interested, you can go online and check out the jquery code !~

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.