|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
orest Smarty n00b
Joined: 28 May 2003 Posts: 3
|
Posted: Wed May 28, 2003 4:53 pm Post subject: Subdirectories and directory structure |
|
|
I am having trouble getting Smarty to work with files in subdirectories under the document root.
The online documentation provides an example similar to what I am trying to achieve: http://smarty.php.net/manual/en/installing.smarty.extended.php. However, after modifying the example for my environment, it failed with errors "problem writing temporary file" and "unable to read template resource".
I have set up the following directories and files:
/home/smarty/libs/ -- Smarty libraries directory
/home/htdocs/ -- web document root directory ($DOCUMENT_ROOT)
/home/htdocs/index.php -- home page (works with Smarty as expected)
/home/htdocs/config.php -- script to initialize environment
/home/htdocs/test/index.php -- page to test Smarty directory traversal
The page at test/index.php (last item above) is where I am encountering the errors.
The config.php file is analogous to the setup.php file in the Smarty online documentation noted above. The home page (which works as expected) does not call the config.php file but uses the Smarty libs directly.
The following is the contents of my config.php file (directories shortened for clarity):
// -------------
require ("/home/smarty/libs/Smarty.class.php"); // this works
class Smarty_smartytest extends Smarty
{
function Smarty_smartytest()
{
$this->Smarty();
$this->template_dir = 'templates';
$this->compile_dir = 'templates_c';
$this->config_dir = 'configs';
$this->cache_dir = 'cache';
$this->caching = true;
$this->assign('app_name','smartytest');
}
}
// -------------
And the following is the contents of my test/index.php file:
// -------------
require ($DOCUMENT_ROOT."/config.php"); // this works
$smarty = new Smarty_smartytest;
$smarty->assign('name','Ned');
$smarty->display('test.tpl');
// -------------
I've tried indicating different directory paths for the various file/directory references, to no avail. My guess is that the config.php doesn't have the correct paths to the template_dir, compile_dir, config_dir, and cache_dir. I've tried several variants there but can't seem to get the correct one. (I'm not familiar with using PHP classes and objects.)
Any suggestions or solutions?
Thanks,
- Orest |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed May 28, 2003 5:15 pm Post subject: |
|
|
use absolute paths in your config.php .
you say that index.php works, but test/index.php doesn't. i assume you have templates_c and templates in /home/htdocs so that "templates_c" is found correctly when using "index.php", but not when using "test/index.php" the latter need "../templates_c" to find the correct templates_c. to avoid these problems, use absolute paths. |
|
Back to top |
|
orest Smarty n00b
Joined: 28 May 2003 Posts: 3
|
Posted: Thu May 29, 2003 12:36 am Post subject: |
|
|
Thanks very much for the suggestions! I gave them a try but, unfortunately, am still getting errors.
First of all (just to make sure I'm being clear), the index.php page at the web root does reference the config.php file, however, it calls the class Smarty directly, not through the class Smarty_smartytest that I had created. The require statement in config.php makes sure that the class Smarty is found.
test/index.php, on the other hand, calls class Smarty_smartytest in the config.php file.
I tried the following variations of paths in my class Smart_smartytest (some shortened here for clarity/security). Following each is the error message displayed when I tried to load test/index.php.
1. /usr/local/virt/74/htdocs/templates (anchored at server root) -- unable to read template resource: "test.tpl" (2x)
2. $DOCUMENT_ROOT.'/templates' -- problem writing temporary file; unable to read template resource: "test.tpl"
3. /htdocs/templates -- problem writing temporary file; unable to read template resource: "test.tpl"
4. /templates -- problem writing temporary file; unable to read template resource: "test.tpl"
5. ../templates -- unable to read template resource: "test.tpl" (x2)
Any other suggestions/ideas?
Thanks,
- Orest |
|
Back to top |
|
orest Smarty n00b
Joined: 28 May 2003 Posts: 3
|
Posted: Thu May 29, 2003 2:07 am Post subject: |
|
|
Problem solved!
Well, thanks to your suggestions and the exercise of going through all the errors one by one, I discovered the error. And boy, do I feel like a goof.
I noticed that the errors weren't consistent when I used the various directory paths in my earlier message. That meant that *sometimes* part of the script *was* working. The error that showed up consistently was the alleged unreadable test.tpl file. In fact, there wasn't one (it wasn't just unable to be read, it was just plain missing) -- hence the error message.
What threw me was that I couldn't figure out what error message belonged to what problem. Once I narrowed down the issues, I was able to pinpoint that the template file was missing.
Thanks again for your help.
- Orest |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|