我正在使用 cakePHP 1.26。
当我尝试使用 requestAction 从 .ctp 访问 COntroller 中的函数时,网页变为空白。
这是代码:
<?php
class TestingController extends AppController {
function hello($id=null){
$IfLoggedIn=$this->Session->check('user');
if($IfLoggedIn){
//search the database
//$result=doing something from the search results
$this->set('userInfo',$result);
return "2";
}
else if(!$IfLoggedIn && $id!=null){
return "1";
}
else if($id==null){
return "0";
}
}
}
然后在 default.ctp 文件中,我使用了上面定义的函数:
<?php
$u = $this->requestAction('/hello');
if($u=="2"){
echo "welcome back, my friend";
}
else{
echo "Hello World";
}
?>
但是当我加载一个网页时,它是空白页。
我不知道代码有什么问题。