如何最小化此PHP代码(How minimize this PHP CODE)

编程入门 行业动态 更新时间:2024-10-28 04:16:41
如何最小化此PHP代码(How minimize this PHP CODE)

有人可以帮忙。 我想最小化我的脏代码,我的逻辑很弱。 先谢谢你..

//These are all fields $prodname = $this->input->post('prodname'); $price = $this->input->post('price'); $qty = $this->input->post('qty'); $desc = $this->input->post('desc'); $status= $this->input->post('status'); // This part I want to minimize, or any shorthand for this code?? if ($prodname != NULL && $price != NULL && $qty != NULL && $desc != NULL && $status != NULL) $datas = $this->controller->add_product($data);

Anyone can help. I want to minimize my dirty code, I'm weak in logic. Thank you in advance..

//These are all fields $prodname = $this->input->post('prodname'); $price = $this->input->post('price'); $qty = $this->input->post('qty'); $desc = $this->input->post('desc'); $status= $this->input->post('status'); // This part I want to minimize, or any shorthand for this code?? if ($prodname != NULL && $price != NULL && $qty != NULL && $desc != NULL && $status != NULL) $datas = $this->controller->add_product($data);

最满意答案

是的,您可以执行以下操作:

//These are the fields coming from form "username" is the name of field $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');

添加要添加的规则,然后您只想确认它是否已经过验证,请使用以下命令:

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

参考: https : //www.codeigniter.com/userguide3/libraries/form_validation.html

Yes you can do the following:

//These are the fields coming from form "username" is the name of field $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');

Add as many rules you want to add and then you just want to confirm if it's validated or not, use this:

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

reference: https://www.codeigniter.com/userguide3/libraries/form_validation.html

更多推荐

本文发布于:2023-08-05 18:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最小化   代码   CODE   PHP   minimize

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!