The first recognition controller of Zend Course

Source: Internet
Author: User
Tags zend zend framework
From the beginning of the second week of PHP, it was open to contact the Zend Framework, but then it was released. At that time did not take notes, and then forget everything, back to regret Ah, now learn it again!
Today to see is the controller, this thing is too big, I also just look at the fur, from the far to the!
The following is a simple controller:

Class Hellocontroller extends Zend_controller_action
{
function Indexaction ()
{
echo "Hi, this are my HelloWorld";
}

function Testaction ()
{
$var 1 = $this->_getparam ("var");
echo "Hello" $book _id;
}



function __call ($action, $args) {
$this->_redirect ('/hello ');
    }
}

The result of the run is this:

Http://localhost/hello/test/var/world will show Hellowrold

When Http://localhost/hello/netaction, the hi is displayed, this is my HelloWorld



In fact, I would like to explain the above two points of color separations:

Red: In Zend, I have receive parameters, whether post or get, as long as:

$this->_getparam ("var");

The form can be,

The final protected function _getparam ($paramName, $default = null) is the private method of the controller, but it takes the second argument as the default and returns the default value when the parameter you want is not obtained.



Blue: The purpose of this function is to go to an address when the access method does not exist (here is: Http://localhost/hello)



</

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.