Regarding the problem of module parameter passing in the MVC framework

WBOY
Release: 2016-10-22 00:14:25
Original
915 people have browsed it

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!

How most people write

<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>
Copy after login
Copy after login

My way of writing

<code>//模块
public function login() {
    $param['userName'] = $_POST('userName');
    $param['passWord'] = $_POST('passWord');
    $param['validCode'] = $_POST('validCode');
    return $param;
  }
  
//控制器  
public function test(){
    $this->login();
}</code>
Copy after login
Copy after login

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

Reply content:

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!

How most people write

<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>
Copy after login
Copy after login

My way of writing

<code>//模块
public function login() {
    $param['userName'] = $_POST('userName');
    $param['passWord'] = $_POST('passWord');
    $param['validCode'] = $_POST('validCode');
    return $param;
  }
  
//控制器  
public function test(){
    $this->login();
}</code>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!