对于我当前(高级)基于yii2的项目,我只需要一个控制器(SiteController).所以没有必要在网址中显示它.这就是为什么我将此规则添加到前端配置:
'urlManager' => [
'rules' => array(
'<alias:product|contact|about>' => 'site/<alias>',
),
Run Code Online (Sandbox Code Playgroud)
这工作正常,localhost/product指向localhost/site/product.
当然,我激活了prettyUrl并将此默认规则添加到公共配置:
'rules' => array(
'<controller:\w+>/<id:\w+>' => '<controller>',
'<controller:\w+>/<action:\w+>/<id:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
Run Code Online (Sandbox Code Playgroud)
现在我想访问这样的GET参数:localhost/product/productname.但我得到错误:
无法解析请求"产品"
但是localhost/site/product/productname工作正常......"productname"应该是$ _GET ['id'].为了实现这一目标,我需要做些什么改变?
谢谢!
我有一个计算素数.现在我想知道PHP需要多长时间进行此计算.我在计算之前和之后都拿了两个微缩胶片并减去它.但结果与我的观察不符.我必须等待两秒钟才能得到结果,但计算结果为0,004 ms.为什么会这样,我如何获得真正的持续时间?
$prim_arr = array();
$start = time();
for ($i = 1; $i <= 20000; $i++) {
$result = NULL;
for ($x = 2; $x < $i; $x++) {
if(!($i % $x)){
$result = $i;
break;
}
}
if (!$result) $prim_arr[] = $i;
}
$end = time();
echo (($end - $start)/1000)." ms";
print_r($prim_arr);
Run Code Online (Sandbox Code Playgroud)