Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Подключение твиг к фреймворку
Форумы портала PHP.SU » » Вопросы новичков » Подключение твиг к фреймворку

Страниц (1): [1]
 

1. imedia - 21 Ноября, 2015 - 19:25:03 - перейти к сообщению
Подключаю так
PHP:
скопировать код в буфер обмена
  1.  
  2.   $config = [
  3.   'paths' => ['/templates', VIEWPATH],
  4.   'cache' => '/cache',
  5. ];
  6. $this->load->library('twig', $config);
  7.  

Выдает ошибки
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant VIEWPATH - assumed 'VIEWPATH'
Filename: controllers/main.php
Line Number: 25

Это codeigniter заругался так, а твиг говорит что дирректории не может найти, хотя дирректории созданы
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'The "VIEWPATH" directory does not exist.' in /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php:94 Stack trace: #0 /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php(76): Twig_Loader_Filesystem->addPath('VIEWPATH', '__main__') #1 /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php(34): Twig_Loader_Filesystem->setPaths(Array) #2 /var/www/clients/client1/web1/web/application/libraries/Twig.php(79): Twig_Loader_Filesystem->__construct(Array) #3 /var/www/clients/client1/web1/web/application/libraries/Twig.php(134): Twig->createTwig() #4 /var/www/clients/client1/web1/web/application/controllers/main.php(57): Twig->render('layouts/prehead...', Array) #5 [internal function]: Main->index() #6 /var/www/clients/client1/web1/web/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) #7 /var/www/clients/client1/web1/web/index.php(202): require_ in /var/www/clients/client1/web1/we b/application/third_party/lib/Tw ig/Loader/Filesystem.php on line 94

как победить?
2. DelphinPRO - 21 Ноября, 2015 - 20:21:02 - перейти к сообщению
imedia пишет:
Use of undefined constant VIEWPATH

Константа не определена. Значит и путь получается отсутствует в конфиге твига
3. imedia - 21 Ноября, 2015 - 20:22:21 - перейти к сообщению
А как и где её определять
4. imedia - 22 Ноября, 2015 - 11:29:10 - перейти к сообщению
Константу я определил на так и дальше есть надпись о том что не существует дирректории кода одна есть может она должна быть в определенном месте?
5. DelphinPRO - 22 Ноября, 2015 - 12:33:27 - перейти к сообщению
imedia пишет:
дальше есть надпись о том что не существует дирректории

Лучше показывай само сообщение об ошибке.
и код, как ты определяешь эту константу.
6. imedia - 22 Ноября, 2015 - 13:08:42 - перейти к сообщению
PHP:
скопировать код в буфер обмена
  1.  
  2. define ("VIEWPATH",'/templates');
  3. $config = [
  4.     'paths' => ['/templates', VIEWPATH],
  5.     'cache' => '/cache',
  6. ];
  7.  

А сообщение об ошибке следующее
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'The "/templates" directory does not exist.' in /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php:94 Stack trace: #0 /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php(76): Twig_Loader_Filesystem->addPath('/templates', '__main__') #1 /var/www/clients/client1/web1/web/application/third_party/lib/Twig/Loader/Filesystem.php(34): Twig_Loader_Filesystem->setPaths(Array) #2 /var/www/clients/client1/web1/web/application/libraries/Twig.php(79): Twig_Loader_Filesystem->__construct(Array) #3 /var/www/clients/client1/web1/web/application/libraries/Twig.php(134): Twig->createTwig() #4 /var/www/clients/client1/web1/web/application/controllers/main.php(59): Twig->render('layouts/prehead...', Array) #5 [internal function]: Main->index() #6 /var/www/clients/client1/web1/web/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) #7 /var/www/clients/client1/web1/web/index.php(202): requ in /var/www/clients/client1/web1/we b/application/third_party/lib/Tw ig/Loader/Filesystem.php on line 94

В корне сайта есть дирректория /templates права ей даны 777

А это тот фрагмент на который ссылается твиг
PHP:
скопировать код в буфер обмена
  1.  
  2.  public function addPath($path, $namespace = self::MAIN_NAMESPACE)
  3.     {
  4.         // invalidate the cache
  5.         $this->cache = $this->errorCache = array();
  6.  
  7.         if (!is_dir($path)) {
  8.             throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path));
  9.         }
  10.  
  11.         $this->paths[$namespace][] = rtrim($path, '/\\');
  12.     }
  13.  

(Добавление)
Все решил, слеши просто были лишние и поначалу не была определена константа это то на что вы меня натолкнули спсибо большое

 

Powered by ExBB FM 1.0 RC1