我在尝试CodeIgniter为min_length和max_length验证约束设置自定义验证消息时收到错误.
这些是我的验证规则:
$this->form_validation->set_rules('username', 'Username', 'required|xss_clean|min_length[6]|max_length[10]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|max_length[20]';
Run Code Online (Sandbox Code Playgroud)
这些是我的自定义验证消息:
$this->form_validation->set_message('min_length[3]', '%s: the minimum of characters is three');
$this->form_validation->set_message('max_length[20]', '%s:the maximum of characters is 20');
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我们有两个字段,但我有许多字段具有不同的最小和最大长度值.它们都有特定的约束验证.此消息不起作用.默认情况下会显示该消息.谢谢你的帮助.
我有一个具有下一个功能的控制器:
class controller {
function __construct(){
}
function myfunction(){
//here is my variable
$variable="hello"
}
function myotherfunction(){
//in this function I need to get the value $variable
$variable2=$variable
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答.如何将函数的变量传递给codeigniter控制器中的其他函数?
我在codeigniter中添加了一个下拉动态
echo form_dropdown('mydrop',$options);
Run Code Online (Sandbox Code Playgroud)
在数据库中调用选项的查询.如何在第一个选项中添加选项:
value="" Select an option with codeigniter
Run Code Online (Sandbox Code Playgroud)
谢谢.
在codeigniter中的视图中,我们可以使用codeigniter为表单编写代码.例如,对于url,codeigniter中的代码是:
<?php
anchor('site/myfunction','Send');
?>
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否更好地在视图中使用html编写此代码:
<a href="site/myfunction">Send </a>
Run Code Online (Sandbox Code Playgroud)
这是一个例子,但问题是视图的所有HTML助手.CodeIgniter的用户指南建议使用PHP函数而不是代码html.php代码向服务器请求而html没有.最好使用CodeIgniter for HTML?我不知道当我使用CodeIgniter的帮助程序时,框架是否考虑过这些请求.
我为我的英语道歉.感谢您的回答.
我通过$idURL 传递一个变量,并以表单形式加载数据,但是当我要验证表单时,$id无法识别该值.
function myfunction() {
$id = $this->uri->segment(4);
echo $id; //yes, print the value
$data_user = $this->admin_model->query_data_user($id);
$direccion = $data_user[0]->address;
$phone = $data_user[0]->phone;
$this->data['address'] = array(
'name' => 'address',
'id' => 'address',
'value' => $address,
'class' => 'input',
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'value' => $phone,
'class' => 'input',
);
echo $id; //yes, print the value
$this->form_validation->set_rules('address', 'Address', 'xss_clean|max_length[100]');
$this->form_validation->set_rules('phone', 'Phone', 'required|xss_clean|max_length[20]|is_natural_no_zero');
if ($this->form_validation->run() == true) {
echo $id; //here NOT …Run Code Online (Sandbox Code Playgroud)