Codeigniter 如何解决;Twig\Error\LoaderError";内码点火器

Codeigniter 如何解决;Twig\Error\LoaderError";内码点火器,codeigniter,twig,Codeigniter,Twig,我正在我的codeigniter文件夹中设置细枝 运行codeigniter应用程序时,它显示以下错误: An uncaught Exception was encountered Type: Twig\Error\LoaderError Message: Unable to find template "forms/admission.php" (looked into: C:\wamp\www\openApplication\application\views). F

我正在我的codeigniter文件夹中设置细枝

运行codeigniter应用程序时,它显示以下错误:

An uncaught Exception was encountered
Type: Twig\Error\LoaderError

Message: Unable to find template "forms/admission.php" (looked into: C:\wamp\www\openApplication\application\views).

Filename: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Loader\FilesystemLoader.php

Line Number: 266

Backtrace:

File: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Loader\FilesystemLoader.php
Line: 161
Function: findTemplate

File: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Environment.php
Line: 351
Function: getCacheKey

File: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Environment.php
Line: 445
Function: getTemplateClass

File: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Environment.php
Line: 423
Function: loadTemplate

File: C:\wamp\www\openApplication\application\vendor\twig\twig\src\Environment.php
Line: 384
Function: load

File: C:\wamp\www\openApplication\application\libraries\Twig.php
Line: 33
Function: render

File: C:\wamp\www\openApplication\application\controllers\Admission.php
Line: 27
Function: render

File: C:\wamp\www\openApplication\index.php
Line: 315
Function: require_once
我想运行twig文件格式(.twig)

我的项目代码如下:

控制器页面

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admission extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */


    public function index()
    {

        $output = "";
        $output .= $this->twig->render('forms/admission');
        $this->output->set_output($output);
    }

}

在下面的配置文件中,我使用php作为文件扩展名。像

$config['twig']['template_ext']='php'

我不使用“php”,而是使用“twig”选项来解决这个问题

$config['twig']['template_ext']='twig'


现在我的.twig扩展文件工作正常。

查看路径的值是多少?这是你定义的常数吗?这应该指向存储模板的文件夹。我没有在VIEWPATH中设置任何值。如何设置此值和位置?只需将
VIEWPATH
更改为文件夹的位置,例如
$config['twig']['template_dir']=\uu dir.//路径/到/文件夹'
viewpath是codeigniter中的一个常量,指向
application/views
,现在我的问题解决了。谢谢你的关心。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


$config['twig']['template_dir'] = VIEWPATH;
$config['twig']['template_ext'] = 'php';
$config['twig']['environment']['autoescape'] = TRUE;
$config['twig']['environment']['cache'] = FALSE;
$config['twig']['environment']['debug'] = FALSE;
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader {
    public function view($template, $data = array(), $return = FALSE) {
        $CI =& get_instance();

        try {
            $output = $CI->twig->render($template, $data);
        } catch (Exception $e) {
            show_error(htmlspecialchars_decode($e->getMessage()), 500, 'Twig Exception');
        }

        // Return the output if the return value is TRUE.
        if ($return === TRUE) {
            return $output;
        }

        // Otherwise append to output just like a view.
        $CI->output->append_output($output);
    }
}