看起来这应该是容易的部分,但我似乎无法实现这一目标.我created和updated字段没有填充.我已经尝试将字段重命名为不同的字段,但没有去.除了架构和设置类(非常基本),如下所示,我错过了什么?
Codeigniter v2.1.2 Datamapper ORM v1.8.2.1
架构:
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1
Run Code Online (Sandbox Code Playgroud)
用户类:
<?php
class User extends DataMapper
{
function User()
{
parent::DataMapper();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用CI_Session类的这个扩展.使用TW Bootstrap创建闪存数据并设置样式.但是,当我将"成功"消息传递给视图时,它根本就没有加载.
我有一个好运,但没有喜悦.
我的控制器看起来像这样..
// Set form Validation
$this->form_validation->set_rules('title', 'Title', 'required|trim|is_unique[films.title]');
if($this->form_validation->run() == FALSE)
{
$data['page_title'] = 'Add New DVD';
$this->load->view('_partials/_header', $data);
$this->load->view('_partials/_menu');
$data['genres'] = $this->genre_model->get_genres();
$data['classification'] = $this->classification_model->get_classifications();
$this->load->view('create', $data);
$this->load->view('_partials/_footer');
}
else
{
// Insert into DB
$film_data = array
(
'title' => $this->input->post('title'),
'genre_id' => $this->input->post('genre'),
'classification_id' => $this->input->post('classification')
);
$this->film_model->create($film_data);
$this->session->set_success_flashdata('feedback', 'Success message for client to see');
redirect('dvd');
Run Code Online (Sandbox Code Playgroud)
我的观点是......
<?php $this->session->flashdata('feedback'); ?>
Run Code Online (Sandbox Code Playgroud)
因此,当我向数据库插入一个新项目时,模型运行,重定向运行,但"set_success_flashdata"不运行.
MY_session库设置为根据CI的默认配置自动加载.
我如何得到这个该死的Flash消息:(?
我正在尝试使用codeigniter和ajax上传图像.我已经有了ajax方法将字段值插入数据库,这是上传文件最简单最简单的方法.这是JQuery自定义函数:
(function($){
jQuery.fn.ajaxSubmit =
function() {
$(this).submit(function(event) {
event.preventDefault();
var url = $(this).attr('action');
var data = $(this).serialize();
$.ajax({
url: url,
type: "POST",
data: data,
dataType: "html",
success: function(msg) {
$('#main').html(msg);
}
});
return this;
});
};
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
我称之为:
$(document).ready(function() {
$('#myForm').ajaxSubmit();
});
Run Code Online (Sandbox Code Playgroud)
该功能工作正常,数据插入数据库,我甚至有一些目录,在上传图像之前在模型中创建,它们被创建但图像根本没有上传.
我知道我需要使用隐藏的Iframe来完成这项工作,但我不知道如何将其集成到我的代码中.
PHP会话类类似于CodeIgniter会话类?存在?
我试图搜索,但我没有得到有用的结果.我正在使用CodeIgniter会话类,它具有如此多的功能:
存储用户的唯一会话ID,用户的IP地址,用户的用户代理数据,上次活动以及手动提供的其他信息.这些信息存储在数据库(MySql)中.该类创建一个cookie,以将唯一会话ID与数据库中的会话ID相匹配.在我看来,这门课非常安全.
我想在CodeIgniter之外使用这个类(不使用CodeIgniter).谁能推荐我一个有这些功能的课程?
谢谢!
我在我的服务器上通过以下URL设置了CodeIgniter应用程序:
http://subdomain.domainame.com/something1/something2/
Run Code Online (Sandbox Code Playgroud)
(我使用了something1和2作为例子)
现在,我可以在使用上述URL时完全正确地访问应用程序,并可以将/index.php/controller/action等添加到最后.
我试图在托管应用程序的同一目录中设置.htaccess文件,但它似乎不起作用.
.htaccess文件包含以下内容:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ something1/something2/index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)
这给了我一个500内部服务器错误.
任何人都可以对此有所了解吗?
在CodeIgniter或PHP中是否可以扩展MySQL语句.例如.如果我有$query1.我可以$query1在另一个$this->db->query()实例中添加:
$query1 = this->db->query("SELECT * FROM users WHERE a = b");
$query1(or 2) = $this->db->query("AND b = c");
Run Code Online (Sandbox Code Playgroud) 我想显示一个像twitter和FB这样的时间格式(3小时前发布,2分钟前发布,等等......)
我试过这段代码没有成功:
function format_interval($timestamp, $granularity = 2) {
$units = array('1 year|@count years' => 31536000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
$output = '';
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$floor = floor($timestamp / $value);
$output .= ($output ? ' ' : '') . ($floor == 1 ? $key[0] : str_replace('@count', …Run Code Online (Sandbox Code Playgroud) 我正在使用exec来运行这样的后台脚本:
$command = "/usr/local/bin/php public_html/r/index.php tools $action process $params > /dev/null &";
exec($command);
Run Code Online (Sandbox Code Playgroud)
问题是:它不工作.
提示:
exec命令已启用(我可以执行任何命令而不会出现问题).有任何想法吗?
我最近跳上了CodeIgniter列车,因为我最终想要为我不断发展的PHP/MySQL项目采用MVC架构.现在我遇到了一个probolemin,就我所能看到的那个早先没有描述过的PAgination configuratino.
可能问题不在于PAgination只是相关而是更一般.在我的第一次尝试中,我只是在控制器方法中填充了配置并将其传递给initialize()方法:
$config['base_url'] = $this->config->base_url() . "/categorie/{$catName}/";
$config['total_rows'] = $this->event_model->get_nrofevents_for_categorie($categorieObject->id, TRUE);
$config['per_page'] = 12;
$config['full_tag_open'] = '<div class="paging">';
$config['full_Tag_close'] = '</div>';
$config['prev_link'] = 'Vorige';
$config['next_link'] = 'Volgende';
$this->pagination->initialize($config);
Run Code Online (Sandbox Code Playgroud)
这很好用.但我有一些其他页面使用相同的分页,其大多数参数相同,只有base_url和total_rows配置属性对于每个页面是不同的.我已将公共配置放在config/pagination.php配置文件中,但没有看到在代码中添加依赖于页面的属性的选项.更一般的是,是否可以将通用配置放在配置文件中并在控制器方法中添加一些自定义属性?对我来说,这似乎是合乎逻辑的,但无法弄清楚如何......我尝试过类似的东西:
$this->load->config('pagination');
$this->config->set_item('next_link', 'blablabla');
Run Code Online (Sandbox Code Playgroud)
但似乎在读取配置文件后立即初始化分页,此代码无效.请问有什么建议?
我正在写的是一个临时禁止脚本,适合那些喜欢用小僵尸网络纠缠我的网站的人.
我唯一的问题是如何取消设置json对象.
我有以下代码
/* JSON blocking script written by Michael Dibbets
* Copyright 2012 by Michael Dibbets
* http://www.facebook.com/michael.dibbets - mdibbets[at]outlook.com
* Licenced under the MIT license http://opensource.org/licenses/MIT
*/
// Turn on error reporting
ini_set("display_errors", 1);
error_reporting(E_ALL);
// Create our codeigniter filepath
$filepath = FCPATH.'pagemodules/blocked.json';
// Load file helper to be able to be lazy
$this->load->helper('file');
// Read the json file
$data = read_file($filepath,'c+');
// Have we succeeded? Then continue, otherwise fail graciously
if($data !== false)
{
// Let's make …Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×8
.htaccess ×1
ajax ×1
apache ×1
date ×1
exec ×1
file-upload ×1
jquery ×1
json ×1
mod-rewrite ×1
mysql ×1
pagination ×1
session ×1
shell-exec ×1
time ×1
timeago ×1
unset ×1