Re: [SMARTY] Directories

From: Date: Sun, 09 Feb 2003 10:39:47 +0000
Subject: Re: [SMARTY] Directories
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7604@lists.php.net to get a copy of this message
Thanks for the rapid reply! i tried to define the paths: <?php define('SMARTY_DIR','http://www.domain.de/include/'); require(SMARTY_DIR.'Smarty.class.php'); $smarty = new Smarty; $smarty->template_dir = 'http://www.domain.de/include/templates/'; $smarty->compile_dir = 'http://www.domain.de/include/templates_c/'; $smarty->config_dir = 'http://www.domain.de/include/configs/'; $smarty->cache_dir = 'http://www.domain.de/include/cache/'; $smarty = new Smarty; $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); $smarty->assign("FirstName",array("John","Mary","James","Henry")); $smarty->assign("LastName",array("Doe","Smith","Johnson","Case")); $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), array("M", "N", "O", "P"))); $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); $smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX")); $smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas")); $smarty->assign("option_selected", "NE"); $smarty->display('http://www.domain.de/include/templates/index.tpl'); ?> I tried it with the absolute path and the document_root of phpinfo. But it doesn't work neither. Here's the error msg if i use these pathes: Fatal error: Cannot instantiate non-existent class: smarty in /www/htdocs/v033802/index.php on line 8 if I use these pathes: "/www/htdocs/v033802/include/templates/" displayed by php info (document root) I get these error messages: Warning: stat failed for /www/htdocs/v033802/templates/index.tpl (errno=2 - No such file or directory) in /www/htdocs/v033802/include/Smarty.class.php on line 1516 Warning: Smarty error: problem writing '/^www^htdocs^v033802^templates^index.tpl.' in /www/htdocs/v033802/include/Smarty.class.php on line 1021 Warning: open_basedir restriction in effect. File is in wrong directory in /www/htdocs/v033802/include/Smarty.class.php on line 1441 Warning: open_basedir restriction in effect. File is in wrong directory in /www/htdocs/v033802/include/Smarty.class.php on line 1128 Warning: Failed opening '/^www^htdocs^v033802^templates^index.tpl' for inclusion (include_path='.:..') in /www/htdocs/v033802/include/Smarty.class.php on line 1128 If I use relative pathes, i obtain this error msg: Warning: Smarty error: unable to read template resource: "index.tpl" in /www/htdocs/v033802/include/Smarty.class.php on line 1021 Sorry for asking such kind of newbie questions but I'm just new to it! Thanks! Felix Ferdinand Beyer <fbeyer@clickhand.de> wrote: On 8 Feb 2003 at 23:32, Felix wrote: > > Hello! > I've just installed smarty into the directories www.domain.com/include/, > www.domain.com/include/templates/, www.domain.com/include/templates_c/ etc. ! > I took the example file that is included in the smarty.zip. It works fine. But if I move it to > www.domain.com/ it doesn't work anymore. I changed the smarty.class.php include path to > include/smarty.class.php but it isn't able to read the template file. > If I create a new folder www.domain.com/include/test/ and move index.php into this directory it > works. Don't ask me why or how! But if I create a further directory, let's take > www.domain.com/include/test/php/ for example, it doesn't work anymore. Do I have to change the > compile path, cache path and the template path everytime I create a file in different folders? If this is the case, how do I have to? > Do I need the document root to change the path like $document_root/include/templates or like > that? > Thanks in advance! > > Felix! Could you please set error_reporting to E_ALL and tell us what kind of error messages you get from Smarty? If I undestood you right, you want to include Smarty.class.php from PHP files in different folders and Smarty doesn't find the templates? This could happen since by default all Smarty dirs are relative and expected relative to the CWD ("Current Working Directory"; usually the directory of the PHP file called from outside). I recommend to use absolute paths since that way it doen't matter what the CWD is. But I do not recommend to apply Smarty's settings directly in the Smarty class, here are the reasons: 1. Every time you want to upgrade Smarty, you'll have to change the settings in the Smarty class file again. 2. You cannot use "dynamic code" within the property declaration, eg. it is not allowed to code var $template_dir = realpath('../templates'); Instead, I recommend to hold the settings central by one of the following ways: 1. Use an init script within the smarty directory that is included by every script that wants to use Smarty: define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); require_once SMARTY_DIR . 'Smarty.class.php'; $smarty = new Smarty(); $smarty->template_dir = ... (...) 2. Use a factory function for Smarty: function get_smarty() { $smarty = new Smarty(); $smarty->template_dir = ... (...) } 3. Use a custom Smarty class. This is the way I usually do it as you can even extend Smarty with your own methods. class AdaptedSmarty extends Smarty { function AdaptedSmarty() { // In the constructor you can set Smarty's properties as you want $this->template_dir = ... (...) } } By using one of the methods above you can use absolute paths for Smarty's directories by either hard-code them or calculate them dynamically (e.g. using __FILE__, SMARTY_DIR, getcwd(), dirname(), realpath(), ...). HTH -- Ferdinand Beyer kloschwein@yahoo.de --------------------------------- Gesendet von http://mail.yahoo.de. Bis zu 100 MB Speicher bei http://premiummail.yahoo.de.

« previous php.smarty.general (#7604) next »