简体   繁体   English

Codeigniter控制器功能

[英]Codeigniter controller functions

In my controller i have a view for registering new members. 在我的控制器中,我有一个注册新成员的视图。

Instead of making a whole new function for that such as, 而不是为此提供全新的功能,

public function show_registration(){
$this->load->view('registration');
}

public function validate_registration(){

}

Instead of doing the one above where i make a function to show the view then a new one to receive the data from the view, i made it like this. 我没有像上面那样做一个显示视图的函数,而是一个新的从视图接收数据的函数,而是这样做的。

public function registration(){
if(array_key_exists('submit',$_POST)){
/////if exist process the data here
}else
$this->load->view('registration');
}

The above if statement, checks if ever there was data submitted to the function if not then it would show the view else it will process the data. 上面的if语句检查是否有数据提交给函数,否则将显示视图,否则它将处理数据。

It seems like more of an ideal way right? 似乎更理想的方式吧? then i thought, what if this could cause problems? 那我想,如果这会引起问题呢?

Is there any chance or possibility this might ruin my project? 有没有机会或可能性破坏我的项目? I am starting right now, and i just want insights whether i should pursue my current way or i should just create a separate one for showing the view. 我现在就开始,我只是想了解我是应该遵循当前的方式还是应该创建一个单独的视图来显示视图。

**EDIT: I just realized, this does not necessarily check all submitted data, but only data submitted by the button of the name 'submit', so as long as i keep the name of the submit button for every form unique as possible then i should be fine. **编辑:我刚刚意识到,这并不一定检查所有提交的数据,而是仅检查按钮名称为“ submit”的数据,只要我保持每个表单的提交按钮的名称尽可能唯一,那么我应该没事。

sample: form for registration, button name should be registration.** 示例:注册表格,按钮名称应为注册**。

Here is an example of what you can do with codeigniter 这是您可以使用Codeigniter进行处理的示例

class Form extends CI_Controller {

    function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}

使用Codeigniter,您必须遵循codeigniter-form-validation来加载视图或提交表单以获取更多信息,请访问此Codeigniter form_validation库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM