How to call other methods in the Laravel controller

Source: Internet
Author: User
phpRoute::controller('user','UserController');//UserController.php//www.test.com/user/regfunction postReg(){}//www.test.com/user/loginfunction postLogin(){    if(reg) {      //判断登陆密码    } esle {      $this-> postReg();//把传递过来的参数去注册   }}

When accessing the Www.test.com/user/login, if the wood has the registration, need to call the Postreg method registration, but $this->postreg () This is the Get method, and the parameters of the post can not pass the past, what should I do?

Reply content:

phpRoute::controller('user','UserController');//UserController.php//www.test.com/user/regfunction postReg(){}//www.test.com/user/loginfunction postLogin(){    if(reg) {      //判断登陆密码    } esle {      $this-> postReg();//把传递过来的参数去注册   }}

When accessing the Www.test.com/user/login, if the wood has the registration, need to call the Postreg method registration, but $this->postreg () This is the Get method, and the parameters of the post can not pass the past, what should I do?

Users to log in, you find that users do not have an account, automatically help to register, your product manager agree with this logic? What if the user submits the wrong information? For example, the password was mistaken. You still have to have a registration page, let the user register themselves.

It is unreasonable to request another action in one action. Of course, you can do it too:
Postreg is an HTTP request address that you can emulate in Postlogin HTTP request Postreg, such as using curl.

There is a more reasonable approach, define a method or class createUser($data) , this method can be called in Postreg, can also be called in Postlogin, where you want to tune can be. The method of verifying registration information can also be placed in that class.

What you really need is code reuse.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.