蛋疼集锦71期,太疼了
MySQL存储过程乱码解决方法
我本地的开发环境是windows,服务器为linux,上传到服务器后出现乱码的问题,把存储过程中的变量指定编码后问题解决
。
DECLARE name VARCHAR(100) CHARACTER SET utf8;
三
25
2011
JavaScript模仿PHP的日期格式化函数
http://joncom.be/code/jquery-phpdate/
$.PHPDate("l, jS F Y H:i:s T", new Date());
用法基本和PHP的date是一样的,很简便,具体请查看作者Blog上的文档
一
29
2011
jQuery Superfish Menu插件的z-index bug
这个BUG在IE6/IE7上才会
.sf-menu, .sf-menu * {
margin:0;
padding:0;
list-style:none;
z-index:9999999 !important; /* 加上这一行就能解决叠层问题 */
}
一
01
2011
自定义CodeIgniter的404错误页面
http://maestric.com/doc/php/codeigniter_404
google一下,找一个国外朋友提供的一个解决方法。
其他几个解决方法。
http://codeigniter.com/forums/viewthread/76340/
http://codeigniter.com/forums/viewthread/90613/
http://codeigniter.com/forums/viewthread/54807/
把MY_Router类放到你的“./application/libraries/MY_Router.php”
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Router extends CI_Router {
var $error_controller = 'error';
var $error_method_404 = 'error_404';
function My_Router()
{
parent::CI_Router();
}
// this is just the same method as in Router.php, with show_404() replaced by $this->error_404();
function _validate_request($segments)
{
// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
{
return $segments;
}
// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
// Set the directory and remove it from the segment array
$this->set_directory($segments[0]);
$segments = array_slice($segments, 1);
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
{
return $this->error_404();
}
}
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
// Does the default controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
{
$this->directory = '';
return array();
}
}
return $segments;
}
// Can't find the requested controller...
return $this->error_404();
}
function error_404()
{
$this->directory = "";
$segments = array();
$segments[] = $this->error_controller;
$segments[] = $this->error_method_404;
return $segments;
}
function fetch_class()
{
// if method doesn't exist in class, change
// class to error and method to error_404
$this->check_method();
return $this->class;
}
function check_method()
{
$ignore_remap = true;
$class = $this->class;
if (class_exists($class))
{
// methods for this class
$class_methods = array_map('strtolower', get_class_methods($class));
// ignore controllers using _remap()
if($ignore_remap && in_array('_remap', $class_methods))
{
return;
}
if (! in_array(strtolower($this->method), $class_methods))
{
$this->directory = "";
$this->class = $this->error_controller;
$this->method = $this->error_method_404;
include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT);
}
}
}
function show_404()
{
include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT);
call_user_func(array($this->error_controller, $this->error_method_404));
}
}
?>
这个是控制器
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once("base.php");
class Error extends Controller {
function error_404()
{
$this->load->view($this->_getTheme().'error_404_view', $this->data);
}
}
?>
九
17
2010
Image_moo Class
Image_moo是一个基于Codeigniter的图片类,比Codeigniter自带的Image_lib类要方便,且功能也很强。
//可以连续操作添加水印和生成不同尺寸的缩略图
$this->image_moo
->load(“image.jpg”)
->make_watermark_text("Text", "FONT.TTF", 25, "#000")
->resize(600,600)
->watermark(2)
->save(“large.jpg”)
->resize(400,400)
->save(“medium.jpg”)
->resize(100,100)
->save(“small.jpg”);
九
12
2010
Codeigniter的Ajax示例
下载后解压缩到自己的CI目录,导入SQL文件就可以直接查看了。示例是用Google Libraries API的Mootools 1.1.1版本,所以无需再自己下载了。
点击下载示例
示例中的Ajax代码
window.addEvent('domready', function(){
$$('a[title=status]').each(function(el){
el.addEvent('click', function(e){
new Event(e).stop(); //停止a标签的跳转
var uri = this.getProperty('href').split("#"); //把URL分割出等下要提交Ajax请求的地址和参数
var value = uri[1].split("-"); //把参数分割为数据库中的id值和当前status的值
new Ajax(uri[0], {
method: 'post', //以post方式提交
data: Object.toQueryString({
//生成querystring格式的请求,示例"id=1&status=1"
id:value[0],
status: value[1] == '1' ? '0' : '1'
}),
//当ajax请求完成时触发的事件
onComplete: function(vars){
var r = Json.evaluate(vars); //把从PHP传递过来的Json字符串转换为Javascript对象
if(r.result){ //判断刚才发送的Ajax请求是否更新成功
this.setProperty('href', uri[0] + '#' + r.id + '-' + r.status);//更新a标签的URL与参数
this.setText( r.status );//设置a标签的新文本为更新后的status值
}
}.bind(this)
}).request();
});
el.addEvent('mouseover', function(){
this.setProperty('title', '');
});
});
});
九
03
2010
