小编Mic*_*ł G的帖子

SlimPHP - 扩展树枝(功能)的奇怪错误

我在PHP Slim(最新版本)中有一些简单的应用程序,它是一个简单的网站,从数据库中获取数据并在twig模板上显示.没有什么花哨.只要我不尝试为树枝添加自定义功能,一切都很完美.

当我添加自定义功能到树枝,在一些服务器上(在localhost laragoon工作正常,在具有相同的PHP版本的生产服务器上,我没有收到此错误:

致命错误:无法在第4行的... twig.php中实例化抽象类Twig_Function

下面是我的twig.php - 错误连接到新的Twig_Function,但老实说,我没有在这里看到任何抽象类...,并且在localhost Laragon它工作正常,生产

任何人都知道如何解决这个问题?

<?php

$twig=$container->get('view')->getEnvironment();
$function = new Twig_Function('fotki', function ($id) use ($container) {
    $files=array();
    $dir=opendir($container->get('settings')['fotki_path'].(int)$id);
    while($file=readdir($dir)){
        if((strlen($file)>3)&&(substr($file,-3)=='jpg')){
            array_push($files,(int)$id.'/'.$file);
            //
            }
    }
    closedir($dir);
    return $files;


});
$twig->addFunction($function);

$function = new Twig_Function('fotkalink', function ($path) use ($container) {
    $tab=explode('/',$path);
    return 'mediaimage/'.$tab[0].'-'.$tab[1];
});
$twig->addFunction($function);
Run Code Online (Sandbox Code Playgroud)

容器中的视图声明:

$container['view'] = function ($c)  {
    $a=[];
    if($c['settings']['env']=='prod')
        $a=[ 'cache' => __DIR__.'/../cache'];
    $view = new \Slim\Views\Twig( __DIR__.'/../templates', $a);
    $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new Slim\Views\TwigExtension($c['router'], $basePath));

    return $view; …
Run Code Online (Sandbox Code Playgroud)

php slim twig

3
推荐指数
1
解决办法
1340
查看次数

标签 统计

php ×1

slim ×1

twig ×1