PHP TP Controller

Source: Internet
Author: User

Read configuration
C Method: $model = C (' Url_model ');
Dynamic configuration: Some configuration is needed in some places, where it is written
C Method: C (' Url_model ', 0);

The name of the controller uses the hump-named method (capitalized in the first letter)

Pre-action: What needs to be done before calling this method
Post action: What you need to do after calling this method
Cases:
Pre-action method
Public Function _before_xianshi ()
{
Echo ' I'm before the show <br/> ';
}
Public Function Xianshi ()
{
echo "Main Page display <br/>";
}
Post-operation method
Public Function _after_xianshi ()
{
Echo ' I'm after the show <br/> ';
}

Action parameter Binding
Public Function Xianshi ($name, $ids)
{
Echo $name. IDs. " Main Page display <br/> ";
}
Pass a parameter: path mode
Http://localhost:8080/thinkphp/index.php/home/main/xianshi/name/zhangsan
Pass two parameters:
http://localhost:8080/thinkphp/index.php/home/main/xianshi/name/zhangsan/ids/666

Jump page
<a href= "/thinkphp/index.php/home/main/xianshi/ids/1/name/zhangsan" > Invoke display Operation </a>

Case sensitivity setting, default false means URL is case-sensitive true means case insensitive
' Url_case_insensitive ' = true,

Template engine normal tag start tag
' Tmpl_l_delim ' = ' <{',
Template engine normal tag end tag
' Tmpl_r_delim ' = '}> ',


Display the values added from the controller in the template
Public Function Ceshi ()
{
$this->assign ("test", "Hello");//Register variable
$this->display ();
}
In the ceshi.html page
<div><{$test}></div>

Input variables
Post method:
Public Function Xianshi ()
{
echo $_post["name"];
}
In the ceshi.html page
<form action= "/thinkphp/index.php/home/main/xianshi" method= "POST" >
<input type= "text" name= "name"/>
<input type= "Submit" value= "Submission"/>
</form>

Gets system constant information (displayed in groups if the parameter is true)
Public Function Ceshi ()
{
Var_dump (Get_defined_constants (true));
}

__controller__ automatically gets to the controller
Under which root directory the __root__ is placed
__app__ fetch to the entry file
__module__ Current Module
__self__ Current operation method (including parameters after Operation method)
__action__ Current operation method (excluding parameters after action method)

Multiple logical implementations of the same method
Public Function Login ()
{
Implement two logic, display page, implement login
if (empty ($_post))
{
$this->display ();
}
Else
{
Implement Login
echo "Implement login";
}
}

PHP TP Controller

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.