Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > PHP: Libraries > [smarty] подключение файл библиотек и настройка


Автор: v_enom 30.9.2007, 19:45
Товарищи, подскажите новичку. Почти та же проблема: не нужны полные пути( для переносимости на другие серваки).

Но не находит smarty.class.php  и другие файлы, если не писать полный путь

Стоит Windows,Denver.

структура каталогов такая(читал мануал, методом тыка получилось запустить...может что не так,не знаю)


у меня апач стоит тут:

C:\WebServers\usr\local\apache\...
                                        \php\...                                     - php.ini  и т.д.
                                         \perl\... 
                         \home\smartysite.ru\www\smarty\...      - тут шаблоны и т.д.
                                                                   \index.php      - файл загрузки сайта

                         \etc\...
                         \tmp\...

а мой Smary_libs стоят тут(пробовал ставить и в C:\WebServers\usr\local\ , все равно один эффект )

С:\smarty\libs\....smarty.class.php




я в  файл php.ini вписал, как в монуале требовалось:

     include_path = ".;C:\smarty\libs\"  но все равно не находит файла smarty.class.php

то же самое и *.tpl 


хочу как мануале 
require_once('Smarty.class.php') 

а не так

require('C:\smarty\libs\Smarty.class.php');

Автор: sw04 1.10.2007, 10:57
в индексе :
Код

include("smarty/lib/Smarty.class.php");

Автор: v_enom 1.10.2007, 14:48
я правильно понял?

Код


<?php   //---------------------------  Functions

include("smarty/lib/Smarty.class.php");
//require('C:\smarty\libs\Smarty.class.php');
 require('Smarty.class.php');
$smarty = new Smarty;

$smarty->template_dir = 'C:/WebServers/home/smarty1.ru/www/smarty/tamplates/';
$smarty->config_dir = ' C:/WebServers/home/smarty1.ru/www/smarty/config/';
$smarty->cache_dir = 'C:/WebServers/home/smarty1.ru/www/smarty/cache/';
$smarty->compile_dir = 'C:/WebServers/home/smarty1.ru/www/smarty/tamplates_c/';
//-----------------------------------------------------------------------------

$smarty->assign('a','artem');

$arr = array(100,101,102);
$smarty->assign('cust',$arr);

$smarty->display($smarty->template_dir.'index3.tpl');
?>




такая фишка не работает. вот что пишет:

Warning: main(smarty/lib/Smarty.class.php): failed to open stream: No such file or directory in C:\WebServers\home\smarty1.ru\www\index3.php on line 3

Warning: main(): Failed opening 'smarty/lib/Smarty.class.php' for inclusion (include_path='.;/usr/local/php/PEAR') in C:\WebServers\home\smarty1.ru\www\index3.php on line 3

Warning: main(Smarty.class.php): failed to open stream: No such file or directory in C:\WebServers\home\smarty1.ru\www\index3.php on line 5

Fatal error: main(): Failed opening required 'Smarty.class.php' (include_path='.;/usr/local/php/PEAR') in C:\WebServers\home\smarty1.ru\www\index3.php on line 5

Добавлено через 4 минуты и 13 секунд
может мне тогда нужно библиотеки Smarty кидать в каждый проект в папку:

C:\WebServers\home\smartysite.ru\www\smarty\libs\Smarty.class.php

а есть другие варианты или так правильно: кидать библиотеку в проекты ?

Автор: sw04 1.10.2007, 22:22

index.php
Код

<?php
//-----------------------------------------------------------------------
// стиль *nix (не забывайте о заглавной 'S')
define('SMARTY_DIR', '/usr/local/lib/Smarty-v.e.r/libs/');

// стиль windows
define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/');
//------------------------------------------------------------------------
require_once(SMARTY_DIR . 'Smarty.class.php');

$smarty = new Smarty();

$smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir = '/web/www.example.com/guestbook/cache/';

$smarty->assign('name', 'Катруська');

//** раскомментируйте следующую строку для отображения отладочной консоли
//$smarty->debugging = true;

$smarty->display('index.tpl');
?> 

Автор: v_enom 2.10.2007, 13:19
я видел этот пример, спасибо. Он-то и ввел меня в заблуждение.



$smarty->template_dir = '/web/www.example.com/guestbook/templates/';

мне не ясно куда кидать файл и что прописывать
 вот тут:   /web/www.example.com/guestbook/templates/';

что будет для меня подобной  директорией?
вот такая?  $smarty->template_dir = '/home/www.example.com/www/example/templates/';
или такая?  $smarty->template_dir = '/home/www.example.com/example/templates/';

(ни с одно из них не работает, пишет 
Smarty error: unable to read resource: "index.tpl" in C:\WebServers\usr\local\smarty\libs\Smarty.class.php on line 1095
)

у меня только так работает:  C:/WebServers/home/www.example.com/www/example/templates/
  

на примере vin.ru сделал так, как в примере:

Код


<?php

// стиль windows
define('SMARTY_DIR', 'C:/WebServers/usr/local/smarty/libs/');
require_once(SMARTY_DIR . 'Smarty.class.php');


$smarty = new Smarty();

$smarty->template_dir = '/home/vin.ru/www/vin/templates/';
$smarty->compile_dir = '/home/vin.ru/www/vin/templates/templates_c/';
$smarty->config_dir = '/home/vin.ru/www/vin/templates/configs/';
$smarty->cache_dir = '/home/vin.ru/www/vin/templates/cache/';

$smarty->assign('name', 'Катруська');

//** раскомментируйте следующую строку для отображения отладочной консоли
//$smarty->debugging = true;

$smarty->display('index.tpl');


?>




$smarty->display('index.tpl'); не видит. нужно прописывать путь прямой

Добавлено @ 13:20
Warning: Smarty error: unable to read resource: "index.tpl" in C:\WebServers\usr\local\smarty\libs\Smarty.class.php on line 1095

Добавлено через 6 минут и 19 секунд
да и еще....я не могу из браузера загрузить index.php если он в любой другой папке, кроме как в sitename.ru/www/
а в примерах к смарти можно видеть и /sitenam.ru/guestbook/htdocs/index.php


я думаю, что мне нужно что-то с include_path сделать, но что....не знаю..помогите можалуйста!

Автор: v_enom 2.10.2007, 22:56
Проблема решилась правильным прописанием в php.ini  пути include_path

вот таким вот образом.

include_path = ".;C:\WebServer\home\go-pear1.ru\www/PEAR;C:\WebServer\usr\local\smarty\libs\;"

(я когда только самый первы раз редактировал php.ini не догадался поискать include_path а прописал в начале свой....получалось,что второй стандартный перекрывает прописанный мной)


sw04, спасибо, что помогал!

M
Guedda
Модератор: Не забываем отмечать вопрос решенным!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)