我有一个像这样的简单链接: <a href="?wp_accept_function=10">Accept</a>
我的想法是,这将运行一个名为wp_accept_function的函数,并传入10的id,我该怎么做?谢谢
这是我到目前为止的代码,但我觉得我出错了,需要将数字传递给函数,然后才能在函数中使用它.谢谢
if ( isset ( $_GET ['wp_accept_function'] ) )
{
function wp_accept_favor ( $id )
{
// JAZZ
}
}
Run Code Online (Sandbox Code Playgroud)
我想你想要这个:
首先,您需要定义该功能.
function wp_accept_favor($id) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
然后,您必须检查参数是否已设置并调用该函数.
if (isset($_GET['wp_accept_function'])) {
// call the function passing the id casted to an integer
wp_accept_favor((int)$_GET['wp_accept_function']);
}
Run Code Online (Sandbox Code Playgroud)
强制转换(int)是为了避免为wp_accept_favor()函数传递非整数类型,但您可以根据需要处理它.
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |