{"id":4556,"date":"2010-07-04T15:58:17","date_gmt":"2010-07-04T06:58:17","guid":{"rendered":"http:\/\/fukata.org\/?p=4556"},"modified":"2017-08-11T22:58:50","modified_gmt":"2017-08-11T22:58:50","slug":"codeigniter-with-twig-1","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/4556\/","title":{"rendered":"[CodeIgniter]Twig\u3068\u9023\u643a\u3057\u3066\u307f\u305f – \u305d\u306e1"},"content":{"rendered":"
PHP\u306e\u8efd\u91cf\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b\u65e5\u672cCodeIgniter\u30e6\u30fc\u30b6\u4f1a<\/a>\u3068DJango\u3084Tiles\u306e\u3088\u3046\u306b\u7d99\u627f\u6a5f\u80fd\u3092\u7528\u3044\u305fPHP\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u300cTwig – The flexible, fast, and secure template language for PHP<\/a>\u300d\u3092\u7c21\u5358\u306b\u9023\u643a\u3055\u305b\u3066\u307f\u307e\u3057\u305f\u306e\u3067\u8a2d\u5b9a\u3092\u66f8\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u305f\u3060\u3001CodeIgniter\u3067\u4f5c\u6210\u3057\u305fHelper\u306a\u3069\u3092Twig\u5185\u3067\u306e\u4f7f\u7528\u307e\u3067\u306f\u691c\u8a3c\u3067\u304d\u306a\u304b\u3063\u305f\u306e\u3067\u307e\u305f\u6642\u9593\u304c\u3042\u308b\u6642\u306b\u3067\u3082\u3084\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u4e0b\u8a18\u3067\u8aac\u660e\u3057\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\u306f\u3053\u3061\u3089\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002 ci-twig-1.0.0.zip<\/a><\/p>\n \u203b\u4e0b\u8a18\u306e\u30bd\u30fc\u30b9\u306fjamiepittock’s codeigniter-twig at master – GitHub<\/a>\u3092\u62dd\u501f\u3057\u3066\u4e00\u90e8\u7de8\u96c6\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u76ee\u6b21<\/p> https:\/\/www.twig-project.org\/installation<\/a>\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fTwig\u306elib\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4ee5\u4e0b\u3092\u683c\u7d0d\u3059\u308b\u3002<\/p>\n PHP\u306e\u8efd\u91cf\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b\u65e5\u672cCodeIgniter\u30e6\u30fc\u30b6\u4f1a\u3068DJango\u3084Tiles\u306e\u3088\u3046\u306b\u7d99\u627f\u6a5f\u80fd\u3092\u7528\u3044\u305fPHP\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u300cTwig – The flexible, f … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[153,783],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/4556"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=4556"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/4556\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=4556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=4556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=4556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u8aac\u660e\u7528\u306b\u30bd\u30fc\u30b9\u3092\u4e00\u90e8\u7de8\u96c6\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u7570\u306a\u308b\u90e8\u5206\u3082\u3042\u308b\u306e\u3067\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u3002<\/p>\n\u5168\u4f53\u306e\u69cb\u6210<\/span><\/h2>\n
\n
\r\n.\r\n`-- system\r\n |-- application\r\n | |-- config\r\n | | `-- twig.php \/\/ Twig\u7528\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\r\n | |-- controllers\r\n | |-- errors\r\n | |-- helpers\r\n | |-- hooks\r\n | |-- language\r\n | |-- libraries\r\n | | |-- Twig \/\/ Twig\u30e9\u30a4\u30d6\u30e9\u30ea\r\n | | `-- Twig.php \/\/ Twig\u30af\u30e9\u30b9\r\n | |-- models\r\n | `-- views\r\n |-- cache\r\n | `-- twig \/\/ Twig\u7528\u30ad\u30e3\u30c3\u30b7\u30e5\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\r\n |-- codeigniter\r\n |-- database\r\n | `-- drivers\r\n |-- fonts\r\n |-- helpers\r\n |-- language\r\n | `-- english\r\n |-- libraries\r\n |-- logs\r\n |-- plugins\r\n `-- scaffolding\r\n |-- images\r\n `-- views\r\n<\/pre>\n<\/blockquote>\n
\u8ffd\u52a0\u30d5\u30a1\u30a4\u30eb<\/span><\/h2>\n
application\/libraries\/Twig<\/span><\/h3>\n
application\/config\/twig.php<\/span><\/h3>\n
\r\n< ?php if (!defined('BASEPATH')) exit('No direct script access allowed');\r\n$config['template_dir'] = APPPATH.'views';\r\n$config['cache_dir'] = BASEPATH.'cache\/twig';\r\n?>\r\n<\/pre>\n
application\/libraries\/Twig.php<\/span><\/h3>\n
\r\n< ?php if (!defined('BASEPATH')) {exit('No direct script access allowed');}\r\n\r\nclass Twig\r\n{\r\n\tprivate $CI;\r\n\tprivate $_twig;\r\n\tprivate $_template_dir;\r\n\tprivate $cache_dir;\r\n\r\n\t\/**\r\n\t * Constructor\r\n\t *\r\n\t *\/\r\n\tfunction __construct()\r\n\t{\r\n\t\t$this->CI =& get_instance();\r\n\t\t$this->CI->config->load('twig');\r\n\t \r\n\t\tini_set('include_path',\r\n\t\tini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries\/Twig');\r\n\r\n\t\trequire_once (string) \"Autoloader\" . EXT;\r\n\t\tlog_message('debug', \"Twig Autoloader Loaded\");\r\n\r\n\t\tTwig_Autoloader::register();\r\n\r\n\t\t$this->_template_dir = $this->CI->config->item('template_dir');\r\n\t\t$this->_cache_dir = $this->CI->config->item('cache_dir');\r\n\r\n\t\t$loader = new Twig_Loader_Filesystem($this->_template_dir);\r\n\t\t$this->_twig = new Twig_Environment($loader, array(\r\n\t\t\t'debug' => true,\r\n\t\t\t'cache' => $this->_cache_dir,\r\n\t\t));\r\n\t}\r\n\r\n\tpublic function view($template, $data = array()) {\r\n\t\t$template = $this->_twig->loadTemplate($template);\r\n\r\n\t\techo $template->render($data);\r\n\t}\r\n}\r\n?>\r\n<\/pre>\n
\u30b5\u30f3\u30d7\u30eb<\/span><\/h2>\n
application\/controllers\/<\/span><\/h3>\n
\r\n< ?php\r\n\r\nclass Welcome extends Controller {\r\n\tfunction Welcome()\r\n\t{\r\n\t\tparent::Controller();\r\n\t\t$this->load-library('twig');\r\n\t}\r\n\t\r\n\tfunction index()\r\n\t{\r\n\t\t$data['name'] = 'Tatsuya';\r\n\t\t$this->twig->view('welcome_message.php', $data);\r\n\t}\r\n}\r\n\r\n\/* End of file welcome.php *\/\r\n\/* Location: .\/system\/application\/controllers\/welcome.php *\/\r\n?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"