{"id":520,"date":"2026-07-10T13:03:38","date_gmt":"2026-07-10T04:03:38","guid":{"rendered":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/520"},"modified":"2026-07-26T21:28:31","modified_gmt":"2026-07-26T12:28:31","slug":"codeigniter%e3%81%a7smarty%e3%82%92%e4%bd%bf%e3%81%86%e6%96%b9%e6%b3%95%e3%81%a8%e3%83%9d%e3%82%a4%e3%83%b3%e3%83%88","status":"publish","type":"post","link":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/520","title":{"rendered":"CodeIgniter\u3067Smarty\u3092\u4f7f\u3046\u65b9\u6cd5\u3068\u30dd\u30a4\u30f3\u30c8"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"501\" src=\"https:\/\/www.marchboy.xyz\/wordpress\/wp-content\/uploads\/2026\/07\/php.png\" alt=\"\" class=\"wp-image-631\" srcset=\"https:\/\/www.marchboy.xyz\/wordpress\/wp-content\/uploads\/2026\/07\/php.png 584w, https:\/\/www.marchboy.xyz\/wordpress\/wp-content\/uploads\/2026\/07\/php-300x257.png 300w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/figure>\n\n\n<h2>\u6982\u8981<\/h2>\n<p>CodeIgniter\u306f\u8efd\u91cf\u304b\u3064\u9ad8\u901f\u306aPHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d3\u30e5\u30fc\u306fPHP\u3067\u8a18\u8ff0\u3057\u307e\u3059\u304c\u3001Smarty\u3068\u3044\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001HTML\u3068\u30ed\u30b8\u30c3\u30af\u3092\u3088\u308a\u660e\u78ba\u306b\u5206\u96e2\u3067\u304d\u307e\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001CodeIgniter\u306bSmarty\u3092\u5c0e\u5165\u3059\u308b\u624b\u9806\u3068\u3001\u5b9f\u8df5\u7684\u306a\u4f7f\u3044\u65b9\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>\u5c0e\u5165\u624b\u9806<\/h2>\n<h3>1. Smarty\u672c\u4f53\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>Composer \u304c\u5229\u7528\u3067\u304d\u308b\u74b0\u5883\u3067\u3042\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067 Smarty \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><code>composer require smarty\/smarty<\/code><\/pre>\n<p>Composer \u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306f\u3001\u516c\u5f0f\u30b5\u30a4\u30c8\u304b\u3089 zip \u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3001<code>application\/third_party\/Smarty<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5c55\u958b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>2. CodeIgniter \u306b Smarty \u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210<\/h3>\n<p> <code>application\/libraries\/Smartyci.php<\/code> \u306b\u4ee5\u4e0b\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;?php\n\nclass Smartyci {\n    public $smarty;\n\n    public function __construct(){\n        \/\/ Composer \u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u5834\u5408\u306f autoload \u3092\u5229\u7528\n        if (file_exists(APPPATH.'..\/vendor\/autoload.php')){\n            require_once(APPPATH.'..\/vendor\/autoload.php');\n        } else {\n            require_once(APPPATH.'third_party\/Smarty\/Smarty.class.php');\n        }\n\n        $this->smarty = new Smarty();\n        \/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u8a2d\u5b9a\n        $this->smarty->setTemplateDir(APPPATH.'views\/smarty\/');\n        \/\/ \u30b3\u30f3\u30d1\u30a4\u30eb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u8a2d\u5b9a\uff08Write \u6a29\u9650\u304c\u5fc5\u8981\uff09\n        $this->smarty->setCompileDir(APPPATH.'..\/storage\/smarty\/compile\/');\n        \/\/ \u30ad\u30e3\u30c3\u30b7\u30e5\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\uff08\u4f7f\u7528\u3057\u306a\u3044\u5834\u5408\u306f\u7121\u52b9\u5316\uff09\n        $this->smarty->setCacheDir(APPPATH.'..\/storage\/smarty\/cache\/');\n        $this->smarty->caching = Smarty::CACHING_OFF;\n    }\n\n    \/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3078\u30c7\u30fc\u30bf\u3092\u5272\u308a\u5f53\u3066\n    public function assign($tpl_var, $value = null){\n        $this->smarty->assign($tpl_var, $value);\n    }\n\n    \/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u8868\u793a\n    public function display($template){\n        $this->smarty->display($template);\n    }\n}\n?&gt;<\/code><\/pre>\n<h3>3. \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067 Smarty \u3092\u547c\u3073\u51fa\u3059<\/h3>\n<p>\u4f8b\u3068\u3057\u3066 <code>application\/controllers\/Welcome.php<\/code> \u306b Smarty \u3092\u5229\u7528\u3057\u305f\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;?php\nclass Welcome extends CI_Controller {\n    public function index(){\n        \/\/ \u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30ed\u30fc\u30c9\n        $this->load->library('smartyci');\n        \/\/ \u30c7\u30fc\u30bf\u306e\u5272\u308a\u5f53\u3066\n        $data = [\n            'title' => 'CodeIgniter + Smarty \u30c7\u30e2',\n            'message' => 'Smarty \u3092\u4f7f\u3063\u305f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u3059\u3002'\n        ];\n        foreach($data as $key => $value){\n            $this->smartyci->assign($key, $value);\n        }\n        \/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u8868\u793a (\u62e1\u5f35\u5b50\u306f .tpl)\n        $this->smartyci->display('welcome.tpl');\n    }\n}\n?&gt;<\/code><\/pre>\n<h3>4. Smarty \u7528\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u4f5c\u6210<\/h3>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f <code>application\/views\/smarty\/<\/code> \u914d\u4e0b\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002\u62e1\u5f35\u5b50\u306f\u6163\u4f8b\u7684\u306b <code>.tpl<\/code> \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;!-- application\/views\/smarty\/welcome.tpl --&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html lang=\"ja\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;title&gt;{$title|escape}&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{$title|escape}&lt;\/h1&gt;\n    &lt;p&gt;{$message|escape}&lt;\/p&gt;\n    &lt;ul&gt;\n        {foreach from=$items item=item}\n            &lt;li&gt;{$item|escape}&lt;\/li&gt;\n        {\/foreach}\n    &lt;\/ul&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h2>\u5b9f\u8df5\u7684\u306a\u30dd\u30a4\u30f3\u30c8<\/h2>\n<ul>\n<li><strong>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f CodeIgniter \u306e\u30d3\u30e5\u30fc\u3068\u306f\u5225\u306b\u7ba1\u7406<\/strong>\u3059\u308b\u3053\u3068\u3067\u3001\u5f93\u6765\u306e PHP \u30d3\u30e5\u30fc\u3068\u6df7\u5728\u3055\u305b\u305a\u306b\u4fdd\u5b88\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/li>\n<li><strong>\u30ad\u30e3\u30c3\u30b7\u30e5\u6a5f\u80fd\u306f\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u6709\u52b9\u5316<\/strong>\u3057\u307e\u3059\u3002\u958b\u767a\u4e2d\u306f <code>caching = Smarty::CACHING_OFF<\/code> \u304c\u4fbf\u5229\u3067\u3059\u3002<\/li>\n<li><strong>\u30c7\u30d0\u30c3\u30b0\u30b3\u30f3\u30bd\u30fc\u30eb<\/strong>\u306f <code>$this->smarty->debugging = true;<\/code> \u3068\u8a2d\u5b9a\u3059\u308c\u3070\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5909\u6570\u306e\u5185\u5bb9\u3092\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/li>\n<li><strong>\u30d7\u30e9\u30b0\u30a4\u30f3\u3084\u30ab\u30b9\u30bf\u30e0\u95a2\u6570<\/strong>\u306f <code>plugins\/<\/code> \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u3057\u3001<code>setPluginsDir()<\/code> \u3067\u30d1\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u3068\u62e1\u5f35\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>CodeIgniter \u306b Smarty \u3092\u7d44\u307f\u8fbc\u3080\u3053\u3068\u3067\u3001\u30d3\u30e5\u30fc\u5c64\u306e\u30ed\u30b8\u30c3\u30af\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u8a00\u8a9e\u306b\u59d4\u8b72\u3057\u3001HTML \u3068 PHP \u306e\u30b3\u30fc\u30c9\u3092\u304d\u308c\u3044\u306b\u5206\u96e2\u3067\u304d\u307e\u3059\u3002\u5c0e\u5165\u624b\u9806\u306f\u6570\u30b9\u30c6\u30c3\u30d7\u3067\u5b8c\u4e86\u3057\u3001<code>assign<\/code> \/ <code>display<\/code> \u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3060\u3051\u899a\u3048\u3066\u304a\u3051\u3070\u3001\u65e2\u5b58\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u5bb9\u6613\u306b\u7d44\u307f\u8fbc\u3081\u307e\u3059\u3002\u305c\u3072\u672c\u7a3f\u306e\u624b\u9806\u3092\u53c2\u8003\u306b\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b Smarty \u3092\u5c0e\u5165\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 CodeIgniter\u306f\u8efd\u91cf\u304b\u3064\u9ad8\u901f\u306aPHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d3\u30e5\u30fc\u306fPHP\u3067\u8a18\u8ff0\u3057\u307e\u3059\u304c\u3001Smarty\u3068\u3044\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001HTML\u3068\u30ed\u30b8\u30c3\u30af\u3092\u3088\u308a\u660e\u78ba\u306b\u5206\u96e2\u3067\u304d\u307e\u3059\u3002\u672c\u8a18 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,35],"tags":[],"class_list":["post-520","post","type-post","status-publish","format-standard","hentry","category-codeigniter","category-php"],"_links":{"self":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/comments?post=520"}],"version-history":[{"count":1,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/520\/revisions"}],"predecessor-version":[{"id":632,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/520\/revisions\/632"}],"wp:attachment":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/media?parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/categories?post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/tags?post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}