我正在使用版本2.1.0的CodeIgniter.我想使用Hooks进行登录验证.这意味着我希望在每个控制器中检查会话数据是否已登录.所以我想使用钩子.我这样做的代码如下:
$config['enable_hooks'] = TRUE;
Run Code Online (Sandbox Code Playgroud)
hooks.php$hook['post_controller_constructor'][] = array(
'class' => 'SessionData',
'function' => 'initializeData',
'filename' => 'loginHelper.php',
'filepath' => 'hooks',
'params' => array()
);
Run Code Online (Sandbox Code Playgroud)
loginHelper.phpclass SessionData{
var $CI;
function __construct(){
$this->CI =& get_instance();
}
function initializeData() {
// This function will run after the constructor for the controller is ran
// Set any initial values here
if (!$this->session->userdata('username')) { // This is line 13
redirect('login');
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它会引发以下错误:
A PHP Error was encountered
Severity: Notice …Run Code Online (Sandbox Code Playgroud) 有没有办法在会话中取消设置所有userdata而不必使用会话销毁?我正在尝试将用户注销,并且需要一次取消设置所有userdata.跟踪会话中设置的所有可能的用户数据变得冗长乏味.我只是想取消设置userdata中可能已经设置的所有内容.
我有下表,并且尝试显示p_total表中所有其他记录的总和。我设法显示了总金额,但如果显示总金额,则仅显示表格第一行的值。尽管p_total的总和正确显示为600。
您能否告诉我下面的代码在哪里出问题:
提前致谢 :)
我的数据库表:
p_id p_name p_quantity p_rate p_total user_id
1 Pepsi 12 30 360 1
2 Hot Breads 12 20 240 1
Run Code Online (Sandbox Code Playgroud)
我的模型中有以下代码
$this->db->select('*,SUM(temporary_table.p_total AS Total');
$this->db->from('temporary_table');
$this->db->where('user_id',$user_id);
$getData = $this->db->get('');
if($getData->num_rows() > 0) {
return $getData->result_array();
}
else {
return null;
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
$this->load->model('mod_sales');
$data['records']= $this->mod_sales->add_to_temporary_table($user_id);
Run Code Online (Sandbox Code Playgroud)
我的看法:
foreach ($records as $row)
{
<td><?php echo $row['p_name'];?></td>
<td><?php echo $row['p_quantity'];?></td>
<td><?php echo $row['p_rate'];?></td>
<td><?php echo $row['p_total'];?></td>
}
<?php echo $row['Total'];?>
Run Code Online (Sandbox Code Playgroud) 编码器.我在这里遇到一个小问题,无法找到解决方案.我正在使用CI中的Active Record构建查询.这是查询的代码:
$this->db->select("u.id AS user_id, u.email, p.display_name, p.first_name, p.last_name, s.status_id, s.message");
$this->db->select("DATE_FORMAT(s.created_at, `Publicado el %d/%m/%Y a las %h:%i %p`) AS created_at", FALSE);
$this->db->join($this->_table_users . ' u', 'u.id = s.user_id');
$this->db->join($this->_table_profiles . ' p', 'p.user_id = u.id');
$this->db->where_in('user_id', $str);
$this->db->where('deleted', 0);
$this->db->from($this->_table . ' s');
$this->db->order_by('s.created_at', 'desc');
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
错误号码:1054
未知列'Publicado el%d /%m /%Y a las%h:%i%p'在'字段列表'中
选择
u.idAS user_id ,u.p.display_name,p.first_name,p.last_name,s.status_id …
现在数据在数据库中看起来像这样:
Hej [indtaster_navn] <br> <br>我forbindelse mednogetpåændringafxxxxxx er der behovforopfølgningpå:<br> <br> xxxx <br> - xxxx <br> - xxxx <br> <br> Jeg vil gerne has enlapbagemelding,nårduharsetpåcaborstående.<br/> <br/> Venlig hilsen <br/> [behandler_navn] <br/> TestGuy <br/> <br/> [lokal_tlf] - lokal <br > 00 00 00 00 - telefon <br> [behandler_email] <br> <br>这个S <br> Something <br> Transformer 1234 <br> 3434 BubbleJ <br> <br>
所以我在发送邮件时有以下代码,重要的是要注意我使用html_entity_decode:
$config['mailtype'] = 'html';
$config['priority'] = 1;
$config['charset'] = 'utf-8';
$this->email->initialize($config);
$this->email->from($this->auth_data->user_email, $this->auth_data->user_firstname . ' ' . $this->auth_data->user_lastname);
$this->email->reply_to($this->auth_data->user_email, $this->auth_data->user_firstname …Run Code Online (Sandbox Code Playgroud) 最近,我正在学习PHP用CodeIgniter框架.我正在处理异常处理但有一件事让我感到惊讶的是,db_debug = TRUE在database.php设置中,异常处理不适用于数据库错误.
如果db_debug = FALSE,我可以抛出并捕获错误,但是当它出现时TRUE,它会直接显示包含数据库错误的页面.
这是我的代码:
在Model:
$this->db->insert('tbl_name',$data);
if (strpos($this->db->_error_message(),'constraint_name') !== FALSE)
{
throw new UniqueConstraintException($this->db->_error_message()); // UniqueConstraintException is customized excpetion
}
Run Code Online (Sandbox Code Playgroud)
在Controller:
try
{
//calling the method from model having above code
}
catch(UniqueConstraintException $ex)
{
echo "There is already item with same item name";
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
即使有db_debug = TRUE设置,我可以在数据库错误上实现异常处理吗?
我在CodeIgniter中开发了我的项目,它在XAMPP服务器上运行良好,但在WAMP服务器上运行不正常.
我改变了
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
和.htaccess我
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)
网站主页正确显示.但是,每当我点击任何链接时,没有链接正在运行服务器主页出现在法语版本中.
只有在URL中有index.php时,项目才能在WAMP上正常运行.
例如
http://localhost/codeigniter/welcome/view (This link doesn't work)
http://localhost/codeigniter/index.php/welcome/view (Links works properly)
Run Code Online (Sandbox Code Playgroud) 香港专业教育学院搜索了包括stackoverflow在内的每个站点.
我已经全局启用了XSS,并且我使用了TinyMCE.在那些页面上,我希望TinyMCE部分没有启用XSS.
在阅读了大约40页后,他们都说要做以下事情:
$tiny_mce = $this->input->post('note'); // xss filtering off
Run Code Online (Sandbox Code Playgroud)
要么
$tiny_mce = $this->input->post('note', FALSE); // xss filtering off
Run Code Online (Sandbox Code Playgroud)
我试过了两个,这是我的模特:
public function edit($id) {
$tiny_mce = $this->input->post('note'); // xss filtering off
$userId = $this->ion_auth->get_user_id();
$data = array(
'note' => $tiny_mce
,'postedBy' => $userId);
$this->db->where('id', $id);
$this->db->update('company_notes', $data);
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么它不工作?任何帮助都会很棒!我真的不想全局关闭XSS,所以我希望采用"每个基础"的方法.
编辑 我刚试过
public function edit($id) {
$this->config->set_item('global_xss_filtering', FALSE);
$tiny_mce = $this->input->post('note'); // xss filtering off
$userId = $this->ion_auth->get_user_id();
$data = array(
'note' => $tiny_mce
,'postedBy' => $userId);
$this->db->where('id', $id);
$this->db->update('company_notes', $data); …Run Code Online (Sandbox Code Playgroud) 我正在构建一个小型应用程序,用户可以使用CodeIgniter登录
我的问题是,当用户登录时,是否建议在会话中存储许多用户的个人信息(例如,他们的用户ID,名称,电子邮件和电话号码)。还是我应该试着忽略个人信息,仅在会话中保留其用户ID?
我不想为了获取一些或用户的基本信息而不断进行数据库查询。
更新资料
我将使用数据库来存储他们的所有信息,我只是想知道他们何时登录,是否建议将他们的数据以及数据库存储在会话中?
谢谢
触发器创建只是不起作用,我尝试了所有我能想到的,例如,像这样:
$this->db->query("DELIMITER //\r\n
CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts`\r\n
FOR EACH ROW BEGIN\r\n
DELETE FROM page_content WHERE page_content.post_id = OLD.post_id;\r\n
END\r\n
//\r\n
DELIMITER ;");
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我都觉得它不会创建触发器,因为Codeigniter只在一行中创建SQL语句.尝试使用和不使用换行符,仍然会收到以下消息:
错误号码:1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER // CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts` FOR EAC' at line 1
DELIMITER // CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts` FOR EACH ROW BEGIN DELETE …Run Code Online (Sandbox Code Playgroud) codeigniter-2 ×10
codeigniter ×9
php ×7
mysql ×3
activerecord ×1
email ×1
encoding ×1
session ×1
tinymce ×1