Archive for 九月, 2010

css hacks

http://www.webdevout.net/css-hacks
CSS的兼容技巧,备忘一下。

自定义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);
	}
}
?>

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”);

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', '');
		});
	});
});
Powered by WordPress | Shop Free Cellular Phones at Bestincellphones.com. | Thanks to Best CD Rates, iCellPhoneDeals.com Offers Best Cell Phone Deals. and Incinerador De Grasa