Smarty integration into the CodeIgniter framework

前端 未结 6 2115
轮回少年
轮回少年 2021-02-07 04:05

A Little Background Information:
I\'ve been looking at a few PHP framework recently, and it came down to two. The Zend Framework or CodeIgniter.

I

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 04:05

    Integrating Smarty in CodeIgniter? It is a breeze! The template system in CodeIgniter is very basic.

    Follow these steps for Smarty 3 in CI 3:

    Download CodeIgniter 3

    Download Smarty 3 and put its content in 'application/third_party/smarty' folder

    Create 'Custom_smarty.php' file in 'application/libraries' and add this code:

    setTemplateDir(APPPATH.'views/templates/');   
        $this->setCompileDir(APPPATH.'views/templates_c/');
      }
    }
    ?>
    

    Create 'templates' & 'templates_c' folders inside 'application/views' folder

    Create simple 'test.tpl' file in 'application/views/templates' folder

    Open 'autoload.php' in 'application/config' folder and add:

    $autoload['libraries'] = array('custom_smarty');
    

    And inside a controller: $this->custom_smarty->display('test.tpl');

    If you are working on localhost set the permissions: sudo chmod -R 777 templates_c. Otherwhise contact your hosting service, if you catch the error Unable to write file. First be sure templates_c folder exists.

    Otherwise you can use another template engine like Twig.

提交回复
热议问题