Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Installing Smarty globally

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
kstingel
Smarty n00b


Joined: 22 Feb 2012
Posts: 2

PostPosted: Wed Feb 22, 2012 5:36 pm    Post subject: Installing Smarty globally Reply with quote

For :
PHP v 5.3.8
Smarty v 3.1.8

I use a single Smarty instance across multiple projects (and sometimes multiple domains). Upon updating to version 3.1.8 of Smarty, everything crashed.

This post details how I resolved the issue.

I have no direct access to php.ini on my live host, so my methods reflect how to go about installing without editing php.ini
-------------------------------------------------------------------
I have a file "init.inc.php" which is located at the root of all my sites, all subsequent pages just
Code:
require_once('init.inc.php');
and load all my third-party libraries.
The methods below all come from init.inc.php.
----------------------------------------------------------------------------
First we need to tell PHP where to look for Includes
Code:
$includes = str_replace("\\", "/", realpath(getcwd() . '/../includes')) . '/';

the above snippet assumes you are working directly in "public_html" and your includes folder is a sibling of "public_html", you may need to change the path if your setup is different.
Code:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $includes);
I develop in Windows, but my Live host is Unix, so I leave PHP to insert the correct PATH_SEPARATOR value for each server.

All looks simple enough up to this point ... alas, this is where Smarty crashed Sad
my previous entry to set the SMARTY_DIR was:
Code:
define('SMARTY_DIR', 'Smarty-3.1.7/libs/');
and everything was working OK because I had set my includes folder using PHP's ini_set() function
Upon updating to 3.1.8, Smarty was unable to find it's plugins folder so it died
I still retain the ini_set() section of my code as other scripts use it, but I've tweaked the Smarty call slightly ...
Code:
define('SMARTY_DIR', $includes.'Smarty-3.1.8/libs/');
this solves Smarty's need for a full path and allows it to locate it's own plugins which in turn returned full Smarty functionality to my sites Smile

init.inc.php (Smarty section)
Code:
<?php
$includes = str_replace("\\", "/", realpath(getcwd() . '/../includes')) . '/';
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $includes);

define('SMARTY_DIR', $includes.'Smarty-3.1.8/libs/');

require_once(SMARTY_DIR . 'Smarty.class.php');


// smarty configuration
class App_Smarty extends Smarty
{
   function __construct()
   {
      parent::__construct();
      $this->setTemplateDir('smarty/templates/');
      $this->setCompileDir('smarty/templates_c/');
      $this->setConfigDir('smarty/configs/');
      $this->setCacheDir('smarty/cache/');
      $this->addPluginsDir('smarty/plugins/');
      // turn on debugging for test site
      if ($_SERVER["SERVER_ADDR"] == "127.0.0.1") {
         $this->debugging = true;
      } else {
         $this->debugging = false;
      }

   }
}
the "App_Smarty" class above uses paths relative to the root of your site Smile
additionally, the closing tag is omitted because we will be continuing our PHP in the calling page
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP