2

Smarty3をSymfony2のテンプレートエンジンとして機能させようとしています。このバンドルをインストールして、Smarty3を機能させようとしています。

https://github.com/noiselabs/SmartyBundle

正常にインストールされますが、インストール手順に記載されているようにAppKernalに追加すると、次のエラーが発生します。

致命的なエラー:クラス'NoiseLabs \ Bundle\SmartyBundle'が20行目の>/home/kevin/workspace/Symfony/app/AppKernel.phpに見つかりません

20行目はregisterBundles()内にあります:new NoiseLabs \ Bundle \ SmartyBundle()、

2番目の、おそらく関連する問題は、app / config / config.ymlで、テンプレートエンジン配列に「smarty」を追加した場合です。

templating:      { engines: ['twig'] }

このエラーがスローされます:

ServiceNotFoundException:サービス「templating」は、存在しないサービス「templating.engine.smarty」に依存しています。

小枝にはsymfonyが付属していることに気づきましたが、このプロジェクトではsmartyを使用する必要があります。私は何かが足りないのですか、それともこれに対する別の解決策がありますか?

カーネルコードは次のとおりです。

<?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');
    }   
}

オートローダーのコードは次のとおりです。

<?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');
4

2 に答える 2

1

マニュアルに問題がありましたが、解決しました。次の手順を使用します。

  1. Smartyをダウンロードして、htdocs ディレクトリに解凍します。その結果、次のようなファイルツリーが得られます: htdocs/Smarty/libs/Smarty.class.php

  2. ZIP ボタンからダウンロードして、Symfony 2 の Smarty Bundle をGithubにダウンロードします。次のフォルダー階層を作成します。 SmartyBundle。

  3. c:/xampp/php/php.ini のように Web サーバーの php.ini に移動し、次の行を検索します。

    include_path = ".;c:\php\includes;"
    

    c:\yourHtdocsFolder\Smarty\libs\ を追加すると、完全な結果が得られます。

    include_path = ".;c:\php\includes;c:\yourHtdocsFolder\Smarty\libs\"
    
  4. ファイル htdocs/yourSymfonyFolder/app/AppKernel.php を開き、以下を追加します。

    $bundles = array(
        [...]
        new NoiseLabs\Bundle\SmartyBundle\SmartyBundle(),
        [...]
    );
    
  5. それでおしまい!Controller src/Acme/HelloBundle/Controller/DefaultController.php で次の例を使用します。

    public function indexAction($name)
    {
        return $this->render('AcmeHelloBundle:Default:index.html.tpl', array('name' => $name);
    }
    
  6. パス src/Acme/HelloBundle/Resources/views/Default/index.html.tpl にテンプレートを作成します。

    Hello {$name}
    
  7. URL www.yourWebsite/app_dev.php/hello/yourName を呼び出します。Routing-File に URL を登録する必要があることに注意してください。

于 2012-05-20T07:18:02.753 に答える