Example of thinkphp5 Framework Calling Other Controller Methods to Implement Custom Jump Interface Function

  • 2021-12-12 08:20:23
  • OfStack

In this paper, the thinkphp5 framework calls other controllers to realize the function of self-defined jump interface. Share it for your reference, as follows:


Loader::action('common/successTips',['mess' => ' Login ','url'=> 'manage/diary/diarys']);
// Public directory common
/**
 *  Operation successful 
 * @param string $mess
 * @param string $url
 * @return mixed
 */
public function successTips($mess = ' Operation ',$url = '')
{
  $this->assign(['tip'=>$mess,'result'=>'OK','url'=>$url]);
  return $this->fetch('common/tips');
}
/**
 *  Operation failed 
 * @param string $mess
 * @param string $url
 * @return mixed
 */
public function failTips($mess = ' Operation ',$url = '')
{
  $this->assign(['tip'=>$mess,'result'=>'NO','url'=>$url]);
  return $this->fetch('common/tips');
}
// Login call 
public function login()
  {
//    return '..';
    $hh = true;
    if ($hh)
    {
      $ww = $this->successTips(' Login ','manage/diary/diarys');
      return $ww;
    }
    else{
      return ' Log in failed ';
    }
  }

After calling here, you need return or return directly

Also, because common is ready to set a function to judge whether to log in, it is ready to skip the login page and use it common::successTips() Call is fine, but here successTips() To use static means to be a static method.

Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".

I hope this article is helpful to PHP programming based on ThinkPHP framework.


Related articles: