Zend Framework Front-End Controller Usage example _php instance

Source: Internet
Author: User
Tags zend zend framework lenovo

This example describes the Zend Framework front-end controller usage. Share to everyone for your reference, specific as follows:

Common methods

1.getInstance ()

Function: Used to get the front-end controller instance.

The code is as follows:

<?php
$front = Zend_controller_front::getinstance ();

By executing the above code, a front-end controller instance is created.

2.setControllerDirectory ()

Function: Lets you tell the distributor where to find the action Controller action Controller class file.

3.getControllerDirectory ()

Function: Used to get the current location of the Controller directory

The code is as follows:

<?php
$front = Zend_controller_front::getinstance ();
$dire = $front->getcontrollerdirectory ();

Environment Accessor method

1.resetInstance ()
function: Clears all current settings

2. (set|get) Defaultcontrollername ()
function: Specify a different name for the default controller, and get the current value

3. (set|get) Defaultactionname ()
function: Specify a different name for the default action, and get the current value

4. (set|get) Request ()
Function: Specifies the request class or object used during the distribution process, and gets the current request object

5. (set|get) Router ()
Function: Specifies the router class or object used in the distribution process, and gets the current object

6. (set|get) Response ()
Function: Specifies the response class or object used during the distribution process, and gets the current object

Front Controller parameters

1.setParam (Name,name,value)
function: A single parameter name that sets a single parameter value of value

2.setParams (Array $params)
Function: Set multiple parameters at once by associative array

3.getParam ($name)
function: Get a single parameter by $name identifier

4.getParams ()
function: Get the entire parameter list at once

5.clearParams ()
function: Empty a parameter (pass in a single string), multiple parameters (incoming array), all parameters (no parameter)

Example:

<?php
require_once ' zend/controller/front.php ';    Load Zend_controller_front class
$front = Zend_controller_front::getinstance ();  Get the front-end controller instance
$front->setparam (' name ', ' John ');        Set the front controller parameter
$name = $front->getparam (' name ');        Gets the Set parameter
echo $name;
echo "<p>";
$array = Array (
  ' g_n ' => ' association ', '
  g_c ' => ' 5000 ', ' g_a ' => '
  Beijing ',
  ' g_p ' => ' Lenovo Group '
);
$front->setparams ($array);
$g = $front->getparams ();
foreach ($g as $k => $v) {
  echo $k. " The value is: ". $v;
  echo "<p>";
}
$front->clearparams ();
$last = $front->getparams ();
foreach ($last as $k => $v) {
  echo $k. " The value is: ". $v;
  echo "<p>";
}

The results are:

The value of John name is: John G_n value is: The value of association G_c is: 5000 g_a value is: The
value of
Beijing g_p is
: Lenovo Group

Because the parameter is cleared, there is no data output for the second call.

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the Zend Framework.

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.