Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Codeigniter访问第三方文件夹中的smarty库?_Php_Codeigniter_Smarty - Fatal编程技术网

Php 如何使用Codeigniter访问第三方文件夹中的smarty库?

Php 如何使用Codeigniter访问第三方文件夹中的smarty库?,php,codeigniter,smarty,Php,Codeigniter,Smarty,我只是需要一些关于在Codeigniter中安装Smarty的帮助 我所做的是: 提取smarty,重命名为smarty并放入第三方文件夹 在autoload.php中启用smarty 在视图中创建模板文件夹(模板、模板) 运行示例页面(在我的示例中,我运行默认索引,其中包含欢迎消息) 结果是: 无法加载请求的类:smarty 在我的autoload.php中,我添加了smarty: $autoload['packages'] = array(APPPATH.'third_party','sma

我只是需要一些关于在Codeigniter中安装Smarty的帮助

我所做的是:

  • 提取smarty,重命名为smarty并放入第三方文件夹
  • 在autoload.php中启用smarty
  • 在视图中创建模板文件夹(模板、模板)
  • 运行示例页面(在我的示例中,我运行默认索引,其中包含欢迎消息)
  • 结果是: 无法加载请求的类:smarty

    在我的autoload.php中,我添加了smarty:

    $autoload['packages'] = array(APPPATH.'third_party','smarty');
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Libraries
    | -------------------------------------------------------------------
    | These are the classes located in the system/libraries folder
    | or in your application/libraries folder.
    |
    | Prototype:
    |
    |   $autoload['libraries'] = array('database', 'session', 'xmlrpc');
    */
    
    $autoload['libraries'] = array('smarty');
    

    我只是不知道我的错误在哪里。我希望你能帮助我。我是smarty的初学者。

    您需要创建一个库类来扩展smarty并自动加载它。在
    /application/library/
    文件夹中创建一个名为
    smartylib.php的新文件

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    // path to SMARTY library
    include APPPATH.'thirdparty/Smarty/libs/Smarty.class.php';
    
    class Smartylib extends Smarty {
    
        function __construct() {
            parent::__construct();
        }
    }
    
    您可能需要在构造中为Smarty执行一些配置工作。请查看上的Smarty文档

    然后,您将能够在控制器中使用它:

    $this->smartylib->assign('name','Ned');
    $this->smartylib->display('index.tpl');
    

    您需要创建一个库类来扩展smarty并自动加载它。在
    /application/library/
    文件夹中创建一个名为
    smartylib.php的新文件

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    // path to SMARTY library
    include APPPATH.'thirdparty/Smarty/libs/Smarty.class.php';
    
    class Smartylib extends Smarty {
    
        function __construct() {
            parent::__construct();
        }
    }
    
    您可能需要在构造中为Smarty执行一些配置工作。请查看上的Smarty文档

    然后,您将能够在控制器中使用它:

    $this->smartylib->assign('name','Ned');
    $this->smartylib->display('index.tpl');
    

    此外,如果您喜欢或需要使用

    $this->smarty->assign('name', 'Ned');
    
    请将“smartylib”对象克隆到
    Controller\uu constructor()
    函数上的“smarty”中

    $this->smarty = clone $this->smartylib;
    

    此外,如果您喜欢或需要使用

    $this->smarty->assign('name', 'Ned');
    
    请将“smartylib”对象克隆到
    Controller\uu constructor()
    函数上的“smarty”中

    $this->smarty = clone $this->smartylib;
    

    谢谢你的评论。我试试看。:)谢谢你的评论。我试试看。:)