Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

help with smarty installation

Posted on 2005-04-05
12
Medium Priority
?
515 Views
Last Modified: 2012-06-27
Hi, I am trying to install and test smarty on a shared hosting account and I am a little lost. I tried to follow the instructions on this page: http://smarty.php.net/quick_start.php but the hello {$name} sample page doesn't work. I must have the directories defined incorrectly.

I have installed the libs directory under my docroot (/www) in a directory named smarty.

It is recommended to create the template and cache directories outside the doc root. So I created a directory /smarty (on the same level as /www) and created the subdirectories there.

So I have:

/smarty/templates
/smarty/templates_c
/smarty/configs
/smarty/cache

and

/www/smarty/libs

I created the sample template and put it in the /smarty/templates directory! And the following is my version of the index.php file:

<?php

// put full path to Smarty.class.php
require($_SERVER['DOCUMENT_ROOT'] . '/smarty/libs/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = '/smarty/templates';
$smarty->compile_dir = '/smarty/templates_c';
$smarty->cache_dir = '/smarty/cache';
$smarty->config_dir = '/smarty/configs';

$smarty->assign('name', 'Me');
$smarty->display('index.tpl');

?>
 
The above doesn't really make sense to me, but it was all I could come up with. I get the error that it can't read the template. Surely because I have incorrectly defined the directory.

Can someone help?

Thanks!
0
Comment
Question by:alpineer
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13708979
did you add smarty directory to your include_dir in the configuration? if not then it could be the problem
0
 

Author Comment

by:alpineer
ID: 13709065
Sorry, but I don't understand your question. In the configuration of what?
0
 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13709133
its a path problem, and maybe it will be easier if you can declare the full path to smarty in your php.ini by adding it to include_dir directories, also see if you define SMARTY_DIR as said in the documentation, define("SMARTY_DIR","/your/path/to/smarty/");
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:alpineer
ID: 13709202
I am on a shared hosting account so I don't think I have access to php.ini. I was just trying to follow the instructions in this quick setup page I mentioned. I also don't think I can do the chown they mention. I did do the chmod to 775.
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13709214
In the error message that says it can't find the template, it should reveal the path it's looking in, and possibly your include path too.
0
 
LVL 11

Accepted Solution

by:
matt_mcswain earned 1000 total points
ID: 13709221
Just give smarty full paths.

$smarty->template_dir = $_SERVER['DOCUMENT_ROOT'] .'/smarty/templates';
$smarty->compile_dir = $_SERVER['DOCUMENT_ROOT'] .'/smarty/templates_c';
$smarty->cache_dir = $_SERVER['DOCUMENT_ROOT'] .'/smarty/cache';
$smarty->config_dir =$_SERVER['DOCUMENT_ROOT'] . '/smarty/configs';
0
 

Author Comment

by:alpineer
ID: 13709330
The documentation says you should either define SMARTY_DIR or provide a full path. I think I am doing the latter by:

require($_SERVER['DOCUMENT_ROOT'] . '/smarty/libs/Smarty.class.php');

No?

0
 
LVL 6

Assisted Solution

by:alextr2003fr
alextr2003fr earned 1000 total points
ID: 13709400
the problem is that your root and smarty are on same levels so try to move one level up from your root to have the right path maybe you should do something like dirname($_SERVER['DOCUMENT_ROOT']) instead of $_SERVER['DOCUMENT_ROOT'] :
$smarty->template_dir = dirname($_SERVER['DOCUMENT_ROOT']).'/smarty/templates';
$smarty->compile_dir = dirname($_SERVER['DOCUMENT_ROOT'])...
etc etc
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13709444
Yeah, you're right, it's one up.
0
 

Author Comment

by:alpineer
ID: 13709591
Bingo!!! That worked.

Though at first I got an error that the directory templates_c must be writable by the web server process. I guess this is because I can't do the chown as per the instructions. I temporarily chmod'ed the directory to 777 and that works, but is this safe? If not how do I get around this?
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13714600
If you can't use chown (why can't you?) and the file is not currently owned by the web server as either owner or group, you have no choice but to use chmod 777.
0
 

Author Comment

by:alpineer
ID: 13714686
Thanks to eveyone for the replies. I just found the smarty forums so I will follow up there. In any event, your help got me started. I was even able to create a looping section! I am now a big fan of smarty.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question