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

Problems with extends of the class Smarty

 
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
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Fri Oct 14, 2011 11:13 pm    Post subject: Problems with extends of the class Smarty Reply with quote

I'm extending the class Smarty of the library smarty and every time I instantiate the class SmartySetup it doesn't find the files that I had configured in the class and if i'm in a subdirectory returns an error saying the file required wasn't found.

Code:
<?php
require($_SERVER['DOCUMENT_ROOT']."/php/lib/smarty/libs/Smarty.class.php");

class SmartySetup extends Smarty{
    public function Setup() {   

        $document_root = $_SERVER['DOCUMENT_ROOT'];

        # seta os diretorios para o smarty
        $this->template_dir = $document_root."/templates/";
        $this->compile_dir  = $document_root."/compile/";
        $this->config_dir   = $document_root."/configs/";
        $this->cache_dir    = $document_root."/cache/";
       
       
        # define se o cache está ligado ou não
        $this->caching        = false;
       
        # define o tempo para expirar o cache
        $this->cache_lifetime = 10;
    }
}
?>


My directory struct

[/img]
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Oct 14, 2011 11:58 pm    Post subject: Reply with quote

Your templates folder is not in document_root but in php folder
Back to top
View user's profile Send private message
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 12:22 am    Post subject: Reply with quote

You mean that I have to put the library in the root folder of the server?
Back to top
View user's profile Send private message Send e-mail
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 12:24 am    Post subject: Reply with quote

Ps: my templates folder is out of php folder. You can check it.
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Oct 15, 2011 12:25 am    Post subject: Reply with quote

$this->template_dir = $document_root."/PHP/templates/";

or better move the templates folder into document_root
Back to top
View user's profile Send private message
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 12:26 am    Post subject: Reply with quote

Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Oct 15, 2011 12:36 am    Post subject: Reply with quote

are you using smarty 3.x and php5? if so:

function setup() { ... $this->Smarty() ...}

should be?

function __construct() { parent::__construct(); ... }
Back to top
View user's profile Send private message Visit poster's website
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 12:59 am    Post subject: Reply with quote

Thanks man, the problem was solved. Thank you so much!

This is the solucion



Code:
<?php
require($_SERVER['DOCUMENT_ROOT']."/breakbeat/php/lib/smarty/libs/Smarty.class.php");

class SmartySetup extends Smarty{
     
    public function __construct() {     
       
        parent::__construct();
       
        //$this->Smarty();
       
        # seta os diretorios para o smarty
        $this->template_dir = $_SERVER['DOCUMENT_ROOT']."/breakbeat/templates/";
        $this->compile_dir  = $_SERVER['DOCUMENT_ROOT']."/breakbeat/compile/";
        $this->config_dir   = $_SERVER['DOCUMENT_ROOT']."/breakbeat/configs/";
        $this->cache_dir    = $_SERVER['DOCUMENT_ROOT']."/breakbeat/cache/";
       
       
        # define se o cache está ligado ou não
        $this->caching = false;
       
        # define o tempo para expirar o cache
        $this->cache_lifetime = 10;
    }
}
?>

Back to top
View user's profile Send private message Send e-mail
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 1:03 am    Post subject: Reply with quote

Are you developer of Smarty ?
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Oct 15, 2011 1:31 am    Post subject: Reply with quote

In Smarty3 the directory setting must be done by corresponding setter function to avoid other side effects.

Code:
<?php
require($_SERVER['DOCUMENT_ROOT']."/breakbeat/php/lib/smarty/libs/Smarty.class.php");

class SmartySetup extends Smarty{
     
    public function __construct() {     
       
        parent::__construct();
       
        //$this->Smarty();
       
        # seta os diretorios para o smarty
        $this->setTemplateDir($_SERVER['DOCUMENT_ROOT']."/breakbeat/templates/");
        $this->setCompileDir($_SERVER['DOCUMENT_ROOT']."/breakbeat/compile/");
        $this->setConfigDir($_SERVER['DOCUMENT_ROOT']."/breakbeat/configs/");
        $this->setCacheDir($_SERVER['DOCUMENT_ROOT']."/breakbeat/cache/");
       
       
        # define se o cache está ligado ou não
        $this->caching = false;
       
        # define o tempo para expirar o cache
        $this->cache_lifetime = 10;
    }
}
?>
Back to top
View user's profile Send private message
rodolfobarretoweb
Smarty Rookie


Joined: 12 Oct 2011
Posts: 8

PostPosted: Sat Oct 15, 2011 4:07 am    Post subject: Reply with quote

Code:
<?php
require($_SERVER['DOCUMENT_ROOT']."/breakbeat/php/lib/smarty/libs/Smarty.class.php");

class SmartySetup extends Smarty{

    public function __construct() {     
       
        parent::__construct();
       
        $document_root = $_SERVER['DOCUMENT_ROOT']."/breakbeat/";
       
        # seta os diretorios para o smarty
        parent::setTemplateDir ($document_root."templates/");
        parent::setCompileDir  ($document_root."compile/");
        parent::setConfigDir   ($document_root."configs/");
        parent::setCacheDir    ($document_root."cache/");
       
       
        # define se o cache está ligado ou não
        $this->caching = false;
       
        # define o tempo para expirar o cache
        $this->cache_lifetime = 10;
    }
}
?>

Back to top
View user's profile Send private message Send e-mail
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