PDA

View Full Version : Installing Smarty Issues


bryantms
12-30-2007, 10:56 PM
I'm trying to install Smarty (the PHP template engine) and am having the following issue. I've got this error:


Warning: require(./Smarty/Smarty.class.php) [function.require]: failed to open stream: No such file or directory in /home/hancockn/public_html/fearandfacts/weblog/smarty.php on line 4

Fatal error: require() [function.require]: Failed opening required './Smarty/Smarty.class.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/hancockn/public_html/fearandfacts/weblog/smarty.php on line 4

When running this file:

<?php
// Use the absolute path for Smarty.class.php
$base_path= basename(dirname(_FILE_));
require($base_path.'/Smarty/Smarty.class.php');
$smarty = new Smarty( );
$smarty->template_dir = $base_path.'/weblog/smarty/templates';
$smarty->compile_dir = $base_path.'/weblog/smarty/templates_c';
$smarty->cache_dir = $base_path.'/weblog/smarty/cache';
$smarty->config_dir = $base_path.'/weblog/smarty/configs';
?>

Now based on the error above I know that it can't find the Smarty.class.php file. As this is an addon domain I'm wondering where this and the other required files need to be? I've put it in the root folder of the domain, the root of the main domain, and the PHP folder of the main domain and have had no luck. I even tried putting these in a PHP folder in the addon domain root.

Does anyone have any advice to help me out? Thanks!

bryantms
12-31-2007, 12:05 AM
So I've got smarty working now, because I used the full path names in the php file:

<?php
// Use the absolute path for Smarty.class.php
require('/home/hancockn/public_html/fearandfacts/Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = '/home/hancockn/public_html/fearandfacts/weblog/smarty/templates';
$smarty->compile_dir = '/home/hancockn/public_html/fearandfacts/weblog/smarty/templates_c';
$smarty->cache_dir = '/home/hancockn/public_html/fearandfacts/weblog/smarty/cache';
$smarty->config_dir = '/home/hancockn/public_html/fearandfacts/weblog/smarty/configs';

?>

That completely eliminate the base directory variables which weren't functioning properly. I'm still concerned that this may be inefficient. Anyone know which method is better?

It's not a big deal anymore know that I have smarty working, but I'm an OCD perfectionist.

Basil
12-31-2007, 02:13 AM
You could probably have just set $base_path to ".", assuming all the links are directly relative to the location of the script.

cpweb
05-27-2008, 12:40 PM
I'm having problems as well. I used smarty locally and recently went with bluehost. Now I get Warning: Smarty error: unable to read resource: "html/index2.php" in /home2/ballasta/public_html/Smarty-2.6.19/libs/Smarty.class.php on line 1092
and my index page looks like this:
<?php
require_once ("setup.php");
require_once('Connections/BallaStatus.php');
$smarty = new ballaStatus();

#$smarty->assign ("name2", "Janae S. Hill");
$x = 0;
mysql_select_db ($database_BallaStatus, $BallaStatus);
$query = "SELECT * FROM users";
$result = mysql_query ($query, $BallaStatus);

if (mysql_num_rows ($result) >= 1){
$x = 1;
$users = array();
while ($rows = mysql_fetch_array ($result, MYSQL_ASSOC)){
array_push ($users, $rows);
}
$smarty->assign ("users", $users);
}

$query = "Select * from products";
$result = mysql_query($query, $BallaStatus);
if(mysql_num_rows ($result) >= 1){
$products = array();
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
array_push($products, $rows);
}
$smarty->assign("products", $products);
}
$smarty->display ("html/index2.php");
?>
I have appeded /home2/ballasta/public_html/ to everything and still nothing happens. What gives?