Code Igniter
[カテゴリ:PHP]
[カテゴリ:Code Igniter]
概要
まだあまり使っていないけど・・・
- Railsの影響を受けたフレームワーク
- コード自動生成など*自動*な機能はない。
- PHP4,5で動く。
- pear未使用。
- ソースはシンプル
- 日本語ドキュメントはないが(&個人的に英語スキル低し)よくできてる。
- 機能多くないので、ドキュメント&ソースでほぼわかる。
リンク
本家
Code Igniter
http://www.codeigniter.com/
User Guide
http://www.codeigniter.com/user_guide/
Wiki
http://www.codeigniter.com/wiki/
Forum
http://www.codeigniter.com/forums/
日本語情報
CILab - CodeIgniter日本語情報・TIPS
http://www.cilab.info/
CodeIgniter ユーザガイド 日本語版 Version 1.5.3
http://userguide.cilab.info/
CodeIgniter in Japan
http://codeigniter.biz/
price-change:blog CodeIgniter:
http://pricewave.blog110.fc2.com/blog-category-4.html
Create it! | CodeIgniter:
http://tuevin.jugem.jp/?cid=12
Tutorials
Pagination with Code Igniter
http://godbit.com/article/pagination-with-code-igniter
Introduction to Code Igniter: Part 1
http://godbit.com/article/introduction-to-code-igniter
Introduction to Code Igniter: Part 2
http://godbit.com/article/introduction-to-code-igniter-part-2
Introduction to Code Igniter: Part 3
http://godbit.com/article/introduction-to-code-igniter-part-3
http://codeigniter.com/wiki/Tutorials/
癖のあるところ
CIの標準のsession機能は、何とcookieに全てのデータを入れる仕組み。
こんなの始めてみた。
当然生では入れておらず、暗号化する仕組みが付いている。
PHPのセッションをベースとしたものもwiki上にある。
Tips
「The URI you submitted has disallowed characters.」エラーがでる。
「http://.../index.php/action/あいう」を表示しようとすると
以下エラーが表示される。
The URI you submitted has disallowed characters.
URIに日本語を含めていると発生するっぽい。
config.php
$config['uri_protocol'] = "AUTO";
を
$config['uri_protocol'] = "REQUEST_URI";
に変更
mysql:シングルクォートを含む文字列をinsertするとエラーになる。
例えば、これを実行するとエラーになる。
$data = array( 'field' => "aaa'aaa", ); $this->db->insert('table', $data);
magic_quote_gpc が on にっている為、off にすること。
get_magic_quotes_gpc() が true のとき、エスケープしないようになっている。
/CodeIgniter_1.5.2/system/database/drivers/mysql/mysql_driver.php
223 function escape_str($str) 224 { 225 if (get_magic_quotes_gpc()) 226 { 227 return $str; 228 } 229 230 if (function_exists('mysql_real_escape_string')) 231 { 232 return mysql_real_escape_string($str, $this->conn_id); 233 } 234 elseif (function_exists('mysql_escape_string')) 235 { 236 return mysql_escape_string($str); 237 } 238 else 239 { 240 return addslashes($str); 241 } 242 }
/CodeIgniter_1.5.2/system/database/drivers/mysqli/mysqli_driver.php
226 function escape_str($str) 227 { 228 if (get_magic_quotes_gpc()) 229 { 230 return $str; 231 } 232 233 return mysqli_real_escape_string($this->conn_id, $str); 234 }
mysql:文字化け回避
coreに手を加える方法
DB接続直後に "SET NAMES utf8" を実行するコードを追加する。
/CodeIgniter_1.5.2/system/database/DB_driver.php
144 // No connection? Throw an error 145 if ( ! $this->conn_id) 146 { 147 log_message('error', 'Unable to connect to the database'); 148 149 if ($this->db_debug) 150 { 151 $this->display_error('db_unable_to_connect'); 152 } 153 return FALSE; 154 } 155 156 // modified core 157 if ($this->dbdriver == 'mysql') { 158 $this->simple_query('SET NAMES utf8'); 159 } 160 161 // Select the database 162 if ($this->database != '') 163 { 164 if ( ! $this->db_select()) 165 { 166 log_message('error', 'Unable to select database: '.$this->database); 167 168 if ($this->db_debug) 169 { 170 $this->display_error('db_unable_to_select', $this->database); 171 } 172 return FALSE; 173 } 174 } 175
MY_Controller を作ってこれを使う方法
標準のControllerを継承してMY_Controllerを作り、
これのコンストラクタで "SET NAMES utf8" を実行する。
/CodeIgniter_1.5.2/system/application/libraries/MY_Controller.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends Controller { function MY_Controller() { parent::Controller(); $this->load->database(); $this->db->query('SET NAMES utf8'); log_message('debug', "MY_Controller Class Initialized"); } } ?>
でもって、MY_Controllerを継承してコントローラを書く。
なお、MY_Controller.phpの読込みはcoreで面倒みてくれるのでrequireなどは不要。
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Hoge extends Controller { : } ?>
最終更新時間:2007年06月25日 10時08分33秒