2017-07-04 4 views
1

Je veux utiliser Brindille dans Yii2 cadre mais il ne fonctionne pas. J'utilise yii2-app-advanced comme projet de base mais je suis nouveau dans le monde Yii donc je pense que je ne configure pas Twig de la bonne manière.Brindille ne fonctionne pas dans Yii2

Tout d'abord je l'ai téléchargé à l'aide:

composer require yiisoft/yii2-twig 

Puis-je suivre ces instructions mais il est pas facile à comprendre: https://github.com/yiisoft/yii2-twig/blob/HEAD/docs/guide/installation.md#configuring-application

Il dit: Pour commencer à utiliser Brindille vous devez configurer composante de vue comme suit:

[ 
    'components' => [ 
     'view' => [ 
      'class' => 'yii\web\View', 
      'renderers' => [ 
       'twig' => [ 
        'class' => 'yii\twig\ViewRenderer', 
        'cachePath' => '@runtime/Twig/cache', 
        // Array of twig options: 
        'options' => [ 
         'auto_reload' => true, 
        ], 
        'globals' => [ 
         'html' => ['class' => '\yii\helpers\Html'], 
        ], 
        'uses' => ['yii\bootstrap'], 
       ], 
       // ... 
      ], 
     ], 
    ], 
] 

Dans quel fichier dois-je coller ce code?


Dans mon fichier index.php j'ai ajouté le code suivant mais il ne fonctionne pas:

{% if true %} 
    <p>It is true.</p> 
{% else %} 
    <p>It is false.</p>   
{% endif %} 

Répondre

1

Je l'ai résolu le faire:

J'ai modifié le backend fichier/config/principal-local-php:

<?php 

$config = [ 
    'components' => [ 
     'request' => [ 
      // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 
      'cookieValidationKey' => 'CPeTotdTU98geIyM7q0PljmCpJbupPN4', 
     ], 
     'view' => [ 
      'class' => 'yii\web\View', 
      'renderers' => [ 
       'twig' => [ 
        'class' => 'yii\twig\ViewRenderer', 
        'cachePath' => '@runtime/Twig/cache', 
        // Array of twig options: 
        'options' => [ 
         'auto_reload' => true, 
        ], 
        'globals' => [ 
         'html' => ['class' => '\yii\helpers\Html'], 
        ], 
        'uses' => ['yii\bootstrap'], 
       ], 
       // ... 
      ], 
     ], 
    ], 
]; 

if (!YII_ENV_TEST) { 
    // configuration adjustments for 'dev' environment 
    $config['bootstrap'][] = 'debug'; 
    $config['modules']['debug'] = [ 
     'class' => 'yii\debug\Module', 
    ]; 

    $config['bootstrap'][] = 'gii'; 
    $config['modules']['gii'] = [ 
     'class' => 'yii\gii\Module', 
    ]; 
} 

return $config; 

Le fichier SiteController.php a la fonction actionIndex() ion. J'ai ajouté l'extension .twig:

public function actionIndex() 
{ 
    return $this->render('index.twig'); 
} 

Et puis j'ai modifié le nom du backend fichier/vues/père/index.php à index.twig.