As the company needs php project development, php is just getting started. In the process of writing button submission, the button events in asp.net are better. Let's take a look at the following code,
Copy codeThe Code is as follows:
<?
Require_once '../inc/EventHelper. php ';
Function Page_Load ()
{
Echo 'all runs at any time <br> ';
If (! Page: IsPostBack ())
{
Echo 'Load Product Category <br> ';
If ($ _ GET ['cmd'] = 'edit ')
{
Echo 'modify and load the product information to be modified <br> ';
}
}
}
Function bAdd_Click ()
{
// Comm: CheckQX ('product management_add ');
Echo "bAdd_Click <br> ";
}
Function bEdit_Click ()
{
// Comm: CheckQX ('product management_modify ');
Echo 'proid = '. $ _ GET ['proid'].' <br> ';
Echo "bEdit_Click <br> ";
}
Function sdfsdfdsf_Click ()
{
Echo "e44444444444444444444 <br> ";
}
?>
<Form name = "aa" method = "post" action = "? <? = Comm: GetParam ()?> ">
<Input type = "submit" name = "bAdd" value = "add"/>
<Input type = "submit" name = "bedit" value = "modify"/>
<Input type = "submit" name = "sdfsdfdsf" value = "ewrewrewr"/>
</Form>
The above code, such as Page_Load, Page. IsPostback, and bAdd_Click, is familiar with asp.net development.
The above code runs the bAdd_Click function when you click the Add button (function seems to be the function). Similarly, click Modify to automatically run the bEdit_Click event. There is no need for too many parameter changes or too many files. If the page features are not very complex, you can use this mode for rapid development.
Let's take a look at the code of the EventHelper. php file:
Copy codeThe Code is as follows:
<?
Class Page
{
// Whether to send data back, 1: Yes
Public static function IsPostBack ()
{
Global $ SYSRunEventName;
Return! Empty ($ SYSRunEventName );
}
// Load and execute the event
Function EventLoad ()
{
Global $ SYSRunEventName;
$ ArrEvent = get_defined_functions ();
$ ArrEventUser = $ arrEvent ['user'];
$ Arr = array_keys ($ _ POST );
Foreach ($ arr as $ row)
{
$ Name = strtolower ($ row );
Foreach ($ arrEventUser as $ row1)
{
$ Name1 = str_ireplace ('_ click', '', $ row1 );
If ($ name = $ name1)
{
$ SYSRunEventName = $ row1;
Break;
}
}
If (! Empty ($ SYSRunEventName ))
{
Break;
}
}
If (function_exists ('page _ load '))
Page_Load ();
$ SYSRunEventRunName = strtolower ($ SYSRunEventName );
If (Page: IsPostBack ())
{
$ SYSRunEventName ();
}
}
}
Class Comm
{
Public static function GetParam ($ params = array (), $ cmd = 'addoverride ')
{
$ AllParam = array ();
If ($ cmd = 'addoverride ')
{
$ ArrKeys = array_keys ($ params );
Foreach ($ arrKeys as $ row)
{
If (! In_array ($ row, array_keys ($ allParam )))
$ AllParam [$ row] = $ params [$ row];
}
}
Else if ($ cmd = 'del ')
{
Foreach ($ params as $ row)
{
Unset ($ _ GET [$ row]);
}
}
$ ArrKeys = array_keys ($ _ GET );
Foreach ($ arrKeys as $ row)
{
If (! In_array ($ row, array_keys ($ allParam )))
$ AllParam [$ row] =_ _ GET [$ row];
}
$ P = '';
$ ArrKeys = array_keys ($ allParam );
Foreach ($ arrKeys as $ row)
{
$ P. = $ row. '='. $ allParam [$ row]. '&';
}
Return rtrim ($ p ,'&');
}
}
Page: EventLoad ();
?>
You can test the above functions. I have run php5.4 successfully, but I have not considered much about the security. I have read some articles about php and may execute php code on the client, because php has many practical features.
For Comm: GetParam, it is often necessary to obtain get parameters or modify parameters. For example, if all url parameters need to be retained during paging, only paging parameters (such as page = 5) are modified ), so I wrote some code on my own.
It mainly utilizes the following features of php:
Function_exists
Get_defined_functions
And uses common form submission principles to implement functions.
Due to the rush of time, it is too late to describe the specific principles. Please forgive me. You can understand the code.