首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让Smarty3与Symfony2一起工作?

如何让Smarty3与Symfony2一起工作?
EN

Stack Overflow用户
提问于 2012-02-03 20:17:44
回答 2查看 4.9K关注 0票数 2

我试图让Smarty 3作为Symfony 2的模板引擎工作。我试图安装这个包以使smarty 3工作:

https://github.com/noiselabs/SmartyBundle

它安装得很好,但是当我按照安装说明中的话将它添加到AppKernal时,我会得到以下错误:

致命错误:在第20行的>/home/kevin/workspace/Symfony/app/AppKernel.php中找不到‘NoiseLabs\Bundle\S烈士包’类

第20行位于registerBundles()中:NoiseLabs\Bundle\S烈性Bundle(),

第二个可能与此相关的问题是,在app/config/config.yml中,如果我在模板引擎数组中添加“智能”:

代码语言:javascript
复制
templating:      { engines: ['twig'] }

它抛出此错误:

ServiceNotFoundException:服务“模板”依赖于不存在的>服务"templating.engine.smarty“。

我意识到小树枝和symfony一起来的,但是对于这个项目,我需要使用智能。我是遗漏了什么,还是有其他的解决办法?

下面是内核代码:

代码语言:javascript
复制
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {   
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
//new NoiseLabs\Bundle\SmartyBundle(),
            new Blog\EntryBundle\BlogEntryBundle(),
        );  

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }   

        return $bundles;
    }   

    public function registerContainerConfiguration(LoaderInterface $loader)
    {   
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }   
}

以下是自动加载程序代码:

代码语言:javascript
复制
<?php

use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Symfony'          => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
    'Sensio'           => __DIR__.'/../vendor/bundles',
    'JMS'              => __DIR__.'/../vendor/bundles',
    'NoiseLabs'        => __DIR__.'/../vendor/bundles',
    'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
    'Doctrine\\DBAL'   => __DIR__.'/../vendor/doctrine-dbal/lib',
    'Doctrine'         => __DIR__.'/../vendor/doctrine/lib',
    'Monolog'          => __DIR__.'/../vendor/monolog/src',
    'Assetic'          => __DIR__.'/../vendor/assetic/src',
    'Metadata'         => __DIR__.'/../vendor/metadata/src',
));
$loader->registerPrefixes(array(
    'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
    'Twig_'            => __DIR__.'/../vendor/twig/lib',
));

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}

$loader->registerNamespaceFallbacks(array(
    __DIR__.'/../src',
));
$loader->register();

AnnotationRegistry::registerLoader(function($class) use ($loader) {
    $loader->loadClass($class);

// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-04 19:44:57

感谢您使用SmartyBundle (我是创建者)。

该死,文件是错的。请更换线路:

代码语言:javascript
复制
new \NoiseLabs\Bundle\SmartyBundle(),

通过

代码语言:javascript
复制
new \NoiseLabs\Bundle\SmartyBundle\SmartyBundle(),
票数 6
EN

Stack Overflow用户

发布于 2012-05-20 07:18:02

我在手册上有问题,但我解决了。使用以下步骤:

  1. 下载智能手机并将其解压缩到htdocs中。因此,您可以得到这样的一个文件:htdocs/Smarty/libs/S烈士.class.php
  2. Github上下载Smarty for Symfony 2,通过ZIP下载。创建以下文件夹-层次结构: htdocs/yourSymfonyFolder/src/NoiseLabs/Bundle/SmartyBundle并将下载的zip与Smarty.php、SmartyBundle.php、SmartyEngine.php和所有其他文件解压缩到htdocs/Symfony/src/NoiseLabs/Bundle/SmartyBundle.
  3. 转到您的Webservers php.ini,如c:/xampp/php/php.ini,搜索以下行: include_path = ".;c:\php\includes;“ 并添加c:\ the \Smarty\libs\,结果如下: ".;c:\php\includes;c:\yourHtdocsFolder\Smarty\libs\“= include_path
  4. 打开File htdocs/yourSymfonyFolder/app/AppKernel.php并添加: $bundles =数组(.新的NoiseLabs\Bundle\S烈士Bundle\S烈士Bundle(),.;
  5. 就这样!在Controller src/Acme/HelloBundle/Controller/DefaultController.php:中使用以下示例 公共函数indexAction($name) {返回=>数组(‘name’=> $name);}
  6. 在Path src/Acme/HelloBundle/Resources/views/Default/index.html.tpl:中创建一个模板 你好{$name}
  7. 拨打网址www.yourWebsite/app_dev.php/hello/yourName。请注意,您必须在路由文件中注册URL。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9134946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档