我正在学习 cakePHP 1.26。
当我在 Controller 中创建一个函数时,我想到了一个问题。
如何最大化 CakePHP 中自定义函数的可用性。
这是我的示例代码:
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($sid==null){
return "0";
}
}
然后在一个 .ctp 文件中,我将使用这个函数:
$u = $this->requestAction('../hello');
if($u==2){
echo "welcome back, my friend";
}
else{
echo "Hello World";
请指教。