我遇到了一个问题......
我有一堆像这样的陈述......
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
Run Code Online (Sandbox Code Playgroud)
然后是限制声明
$this->db->limit($limit, $offset);
Run Code Online (Sandbox Code Playgroud)
最后我得到了声明
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要在我的限制语句之前计算结果,以获得没有限制的总行数.所以我尝试了这个..
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
$num_rows = $this->db->count_all_results();
$this->db->limit($limit, $offset);
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
这将使用where语句对我的行进行计数.但是,get语句现在获取没有先前where语句工作的记录.
它是不可见的,但有大量的代码处理更多的语句,并抓住网址中的东西,所以我宁愿不执行两次数据检索,以解决这个问题...
干杯!
我想知道是否有任何简单的方法在代码点火器中调试路由?
我希望能够在日志中看到以下内容:
Client sent : apps/something
Route found : apps/(:any) --> applications/searchbyname/$1
Redirecting : apps/something --> applications/searchbyname/something
//and just cause we can lets make the searchbyname function not exist
ERROR - 2012-09-16 22:10:05 --> 404 Page Not Found --> applications/searchbyname/something
Run Code Online (Sandbox Code Playgroud)
基本上它意味着我们可以看到我们何时到达路线以及它何时尝试加载.
有没有办法在这些方面启用某些东西?
我想用名为csrf_cookie_name的 cookie设置一个带有此函数的值$ this-> security-> get_csrf_hash(); 但是,它不起作用.
我在我的控制器中有这个:
$csrf_cookie_value = $this->security->get_csrf_hash();
$this->input->set_cookie('csrf_cookie_name', $csrf_cookie_value);
echo $this->input->cookie('csrf_cookie_name');
die();
Run Code Online (Sandbox Code Playgroud)
但它不起作用,没有任何回应.
如果我只尝试这个:
$csrf_cookie_value = $this->security->get_csrf_hash();
echo $csrf_cookie_value;
Run Code Online (Sandbox Code Playgroud)
我工作,生成的字符串被回显.
所以,我认为接下来的两行中的某些内容是错误的:
$this->input->set_cookie('csrf_cookie_name', $csrf_cookie_value);
echo $this->input->cookie('csrf_cookie_name');
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议.
嗨,我需要验证这样的多维形式
<input type="text" class="input-xlarge span5 req" id="contact_first_name" name="hotel[<?=$id?>][contact_first_name]" value="<?= set_value('hotel[contact_first_name]') ?>">
<input type="text" class="input-xlarge span5 req" id="contact_last_name" name="hotel[<?=$id?>][contact_last_name]" value="<?= set_value('hotel[contact_last_name]') ?>">
Run Code Online (Sandbox Code Playgroud)
我不知道最终数组的维度,因为输入是通过jquery动态添加的.
我在服务器端使用Codeigniter Form_Validation,在客户端使用JQuery Validator通过JQuery.
这是我的form_validation规则
$config['add_hotel'] = array(
array(
'field' => 'hotel[][hotel_name]',
'label' => 'Hotel Name',
'rules' => 'required'
),
array(
'field' => 'hotel[][contact_first_name]',
'label' => 'First Name',
'rules' => 'trim|required'
),
array(
'field' => 'hotel[][contact_last_name]',
'label' => 'Last Name',
'rules' => 'trim|required'
),
Run Code Online (Sandbox Code Playgroud)
这就是我通过jquery验证器做的方式
$("#add_hotel").validate({
rules: {
"hotel[][hotel_name]": "required"
/* errorElement: "div",
wrapper: "div"*/
},
messages: {
"hotel[][hotel_name]": …Run Code Online (Sandbox Code Playgroud) 我已经设置了codeigniter来上传小于2MB的小文件,并且工作正常.但我无法上传大型文件20MB>
function stage1()
{
ini_set('upload_max_filesize', '200M');
ini_set('post_max_size', '200M');
ini_set('max_input_time', 3000);
ini_set('max_execution_time', 3000);
$config['upload_path'] = './temp/';
$config['allowed_types'] = 'zip';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定上面的代码有什么问题.我重写php.ini接受更大的文件,并花更多的时间执行脚本,但它仍然返回相同的错误:
You did not select a file to upload.
Run Code Online (Sandbox Code Playgroud)
同样,这适用于小文件但不适用于大文件.
编辑:原来我的服务器提供商有限的文件上传,所以除了FTP文件之外没有解决方案.
<?php foreach($products as $product) : ?>
<li><a href="<?php echo base_url(); ?>main/products/<?php echo $product->id; ?>">
<?php echo $product->name; ?> </a></li>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
所以上面的代码获取了a中的所有记录DB并生成链接.表中的100条记录 - 我想将设计分成5列.所以我会这样做,CSS但我需要能够附上
<ul> on every 20 records</ul>
Run Code Online (Sandbox Code Playgroud)
我怎么能count循环并做到这一点?
我似乎遇到了以下代码的问题.当查询没有返回任何内容时,我无法获取插入查询.但是当db中有一行时,else语句会正确运行.有人知道为什么会发生这种情况吗?
$query5 = $this->db->get_where('loggedstatus', array('userid_loggedstatus' => $userid));
if ($query5->num_rows() < 0) {
$data1 = array('isLoggedIn_loggedstatus' => 'yes', 'userid_loggedstatus' => $userid);
$this->db->insert('loggedstatus', $data1);
} else {
$data = array('isLoggedIn_loggedstatus' => 'yes');
$this->db->where('userid_loggedstatus', $userid);
$this->db->update('loggedstatus', $data);
}
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚我在验证规则上做错了什么,因为它说这个错误.
验证规则:
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|regex_match[a-z0-9]');
Run Code Online (Sandbox Code Playgroud)
错误:
严重性:警告
消息:preg_match()[function.preg-match]:分隔符不能是字母数字或反斜杠
我在看这个.
我的查询返回10,000行,通常会填满内存
我目前在做:
$this->db->get()->result_array();
Run Code Online (Sandbox Code Playgroud)
有没有办法不将所有数据加载到内存中并使用某种游标?似乎结果和结果数组都是数组.(一个是对象数组,另一个是数组数组)
客户端要求记录所有GET/POST请求并将其存储90天以用于其应用程序.我写了一个HOOK,似乎记录了一些GETS/POSTS,但数据少于我的预期.例如,在提交表单数据时,条目似乎不会放入日志中.有人写过类似的东西吗?
这是我到目前为止的版本:
class Logging {
function __construct() {
$this->CI =& get_instance();
}
function index() {
$this->CI->load->model('Logging_m');
$this->CI->load->model('Portal_m');
//get POST and GET values for LOGGING
$post = trim(print_r($this->CI->input->post(), TRUE));
$get = trim(print_r($this->CI->input->get(), TRUE));
$this->CI->Logging_m->logPageView(array(
'portal_id' => $this->CI->Portal_m->getPortalId(),
'user_id' => (!$this->CI->User_m->getUserId() ? NULL : $this->CI->User_m->getUserId()),
'domain' => $_SERVER["SERVER_NAME"],
'page' => $_SERVER["REQUEST_URI"],
'post' => $post,
'get' => $get,
'ip' => $this->CI->input->ip_address(),
'datetime' => date('Y-m-d H:i:s')
));
}
}
Run Code Online (Sandbox Code Playgroud)
此数据存储在名为"Logging_m"的模型中,如下所示:
<?php
class Logging_m extends CI_Model {
function __construct() {
parent::__construct();
}
function logPageView($data) { …Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×6
logging ×2
mysql ×2
activerecord ×1
arrays ×1
css ×1
database ×1
debugging ×1
get ×1
hook ×1
jquery ×1
post ×1
upload ×1
validation ×1