メメメモモ

プログラミング、筋トレ、ゲーム、etc

ガラケー用に文字コード変換

まだ実機チェックとかしてない。



Controller_Templateを使っているときは、afterメソッドで以下のようなロジックを書くことになりそう。

class Controller_Hoge extends Controller_Template
{
	public function after($response)
	{
		$response = parent::after($response);

		if ( Agent::is_mobiledevice() )
		{
			$body = $response->body();
			$body = mb_convert_encoding($body, 'SJIS', 'UTF8');

			$response->body($body);

			$response->set_header('Cache-Control', 'no-cache', true);
			$response->set_header('Content-Type', 'text/html; charset=Shift_JIS', true);
		}

		return $response;
	}
}