1. Recently, I noticed such a phenomenon during the development process. Usually CURD operations on data are placed in the module. Just call in the controller and pass in the corresponding parameters! I personally dislike this way of passing parameters through formal parameters! I'm wondering if we can receive parameters in the module and process them? In this way, the module can be called casually in other places? You can understand what parameters this module requires by yourself!
<code>//模块 public function login($userName,$passWord,$validCode) { $param['userName'] = $userName; $param['passWord'] = $passWord; $param['validCode'] = $validCode; return $param; } //控制器 public function test(){ $userName = $_POST['userName']; $passWord= $_POST['passWord']; $validCode= $_POST['validCode']; $this->login($userName,$passWord,$validCode)); }</code>
<code>//模块 public function login() { $param['userName'] = $_POST('userName'); $param['passWord'] = $_POST('passWord'); $param['validCode'] = $_POST('validCode'); return $param; } //控制器 public function test(){ $this->login(); }</code>
But now most people use the first way of writing! I admit that my writing method may cause problems when running from the command line! But I think for the simplicity of the code, I will choose to encapsulate a function to adapt my writing method to various scenarios
1. Recently, I noticed such a phenomenon during the development process. Usually CURD operations on data are placed in the module. Just call in the controller and pass in the corresponding parameters! I personally dislike this way of passing parameters through formal parameters! I'm wondering if we can receive parameters in the module and process them? In this way, the module can be called casually in other places? You can understand what parameters this module requires by yourself!
<code>//模块 public function login($userName,$passWord,$validCode) { $param['userName'] = $userName; $param['passWord'] = $passWord; $param['validCode'] = $validCode; return $param; } //控制器 public function test(){ $userName = $_POST['userName']; $passWord= $_POST['passWord']; $validCode= $_POST['validCode']; $this->login($userName,$passWord,$validCode)); }</code>
<code>//模块 public function login() { $param['userName'] = $_POST('userName'); $param['passWord'] = $_POST('passWord'); $param['validCode'] = $_POST('validCode'); return $param; } //控制器 public function test(){ $this->login(); }</code>
But now most people use the first way of writing! I admit that my writing method may cause problems when running from the command line! But I think for the simplicity of the code, I will choose to encapsulate a function to adapt my writing method to various scenarios