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

converting extension from 2+ to 3.1

 
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
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Tue Jan 06, 2015 7:54 pm    Post subject: converting extension from 2+ to 3.1 Reply with quote

Hi, im trying to convert this from 2+ to 3.1 but its giving me this message.

Quote:
Uncaught --> Smarty: PHP5 requires you to call __construct() instead of Smarty() <--
thrown in /home/duran6/public_html/affiliatedev/smarty/sysplugins/smarty_internal_templatebase.php on line 855


Code:


require_once('smarty/Smarty.class.php');

class gXpSmarty extends Smarty
{
   
        function __construct()
        {
          parent::__construct();

          //function gXpSmarty()
      //{


      global $gXpConfig;

      $this->Smarty();
                $this->template_dir = $gXpConfig['templates'].$gXpConfig['tmpl'].'/';
      $this->compile_dir  = 'templates_c/'; // old tmp/';
      $this->config_dir   = 'configs/';
      $this->cache_dir    = 'cache/';

      $this->caching = false;

   }//close function construct
 
}//close class gXpSmarty




is it because of $this->Smarty(); what do i use instead of that if thats the issue.

UPDATE: i did find an example here..

Code:

require(SMARTY_DIR . 'Smarty.class.php');
// smarty configuration
class Guestbook_Smarty extends Smarty {
    function __construct() {
      parent::__construct();
      $this->setTemplateDir(GUESTBOOK_DIR . 'templates');
      $this->setCompileDir(GUESTBOOK_DIR . 'templates_c');
      $this->setConfigDir(GUESTBOOK_DIR . 'configs');
      $this->setCacheDir(GUESTBOOK_DIR . 'cache');
    }
}


so now i have

Code:

require_once('smarty/Smarty.class.php');

class gXpSmarty extends Smarty
{
   
        function __construct()
        {
          parent::__construct();

   
      global $gXpConfig;

      $this->setTemplateDir = $gXpConfig['templates'].$gXpConfig['tmpl'].'/';
      $this->setCompileDir  = 'templates_c/'; // old tmp/';
      $this->setConfigDir   = 'configs/';
      $this->setCacheDir    = 'cache/';

      $this->caching = false;

           
   }//close function con
 
}//close class gXpSmarty


$gXpSmarty->assign_by_ref('config', $gXpConfig);

bunch of those which i know creates a notice i need to see what replaces assign_by_ref



and now i get this


Quote:
PHP Notice: Undefined property: gXpSmarty::$setTemplateDir in /home/xxxxxx/public_html/xxxxxx/smarty/Smarty.class.php on line 763
PHP Notice: Undefined property: gXpSmarty::$setCompileDir in /home/xxxxxx/public_html/xxxxxx/smarty/Smarty.class.php on line 763
PHP Notice: Undefined property: gXpSmarty::$setConfigDir in /home/xxxxxx/public_html/xxxxxx/smarty/Smarty.class.php on line 763
PHP Notice: Undefined property: gXpSmarty::$setCacheDir in /home/xxxxxx/public_html/xxxxxx/smarty/Smarty.class.php on line 763
PHP Fatal error: Uncaught --> Smarty: Call of unknown method 'assign_by_ref'. <--
thrown in /home/xxxxxx/public_html/xxxxxx/smarty/sysplugins/smarty_internal_templatebase.php on line 858
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Jan 06, 2015 10:55 pm    Post subject: Reply with quote

parent::__construct()
Please read http://php.net/OOP
And remove that require line. It is ambiguous and unnecessary. Use class autoloading.
Back to top
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Wed Jan 07, 2015 2:10 am    Post subject: Reply with quote

thanks so much,

i have been doing some reading on the autoload but it seems its not a simple process as i thought it might be. I have checked out some samples and so far it appears its about 20 lines of code and including several functions to get the autoload opperational. Just not sure thats the best way right now, i just assumed that a new version meant things would be more dev friendly lol...


Just out of curiosity i also checked some of my software i use such as WHMCS for hosting and its running smarty 2.6.28 so im not really sure why im updating my software to 3+ with all the extra hassle, it would actually save me alot of dev time to just leave it as is and dev other features for the software. i really dont see a huge benefit to upgrading to 3+ but i do see a whole lot of work involved in doing so.

Its something ill have to do more reading on for sure to see which is the best path to follow.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jan 07, 2015 6:21 am    Post subject: Reply with quote

Autoloading is actually 0(zero) lines of code, once you have it all set.

This is not "extra hassle", this is "keeping yourself current".
If updating from 2.x to 3.x takes a toll, this means, you've done wrong things with 2.x that you shold've never ever done to begin with.
In all my projects, changing from 2.x to 3.x was as simple as replacing one library with another. The little issues were only due to change in behavior of some plugins, and were easy to fix.
Back to top
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Wed Jan 07, 2015 6:35 am    Post subject: Reply with quote

thanks for the reply, it will certainly give me something to sleep on tonight. The main issue is im just not changing from 2.6.28 to 3+ smarty, i am also changing from mysql to the mysqli library. Which i have done on other scripts and it was as easy as changing some syntax. But with this script its not liking it one bit and crashes with the slightest change to either smarty or the mysqli library....

The main dif is that the other scripts were not all packed with one class after another, it was pretty straight forward. I never write or use classes unless i have to because i suck at them totally.. I may to things the harder way sometimes but at least i can follow it and totally understand it lol. I have done some pretty amazing things without a single class object lol...

But i guess those days are gone and ill have to learn this stuff.

I think i have gotten myself into a sticky wicket here lol...

Thanks again... ill sleep on it. Smile

PS - my whole point about WHMCS is that they are a major company selling thousands of copies all over the world of their software and also part of cPanel now. They are running an older version, which tells me their devs must agree its safe to do so. I was not saying that should not upgrade i was just thinking if the big boys dont do it then maybe i shouldnt either ya know.
Back to top
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Wed Jan 07, 2015 6:37 am    Post subject: Reply with quote

durangod wrote:
thanks for the reply, it will certainly give me something to sleep on tonight. The main issue is im just not changing from 2.6.28 to 3+ smarty, i am also changing from mysql to the mysqli library. Which i have done on other scripts and it was as easy as changing some syntax. But with this script its not liking it one bit and crashes with the slightest change to either smarty or the mysqli library....

The main dif is that the other scripts were not all packed with one class after another like the current one im working on. It was pretty straight forward. I never write or use classes unless i have to because i suck at them totally.. I may do things the harder way sometimes but at least i can follow it and totally understand it lol. I have done some pretty amazing things without a single class object lol...

But i guess those days are gone and ill have to learn this stuff.

I think i have gotten myself into a sticky wicket here lol...

Thanks again... ill sleep on it. Smile

PS - my whole point about WHMCS is that they are a major company selling thousands of copies all over the world of their software and also part of cPanel now. They are running an older version, which tells me their devs must agree its safe to do so. I was not saying that should not upgrade i was just thinking if the big boys dont do it then maybe i shouldnt either ya know.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jan 07, 2015 7:32 am    Post subject: Reply with quote

Changing mysql to mysqli by renaming functions used is as pointless, as changing "echo" to "print".
You gain exactly zero benefit from such change, but may cause extra headache in the future.
The problem with big companies is that they make a project they never intend to use themselves. Thus all the problems when you actually try to use it.
Back to top
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Wed Jan 07, 2015 8:27 pm    Post subject: Reply with quote

Dont think i ever said i was just changing functions but the syntax inside the functions yes. And yes the only benefit would be to get off a deprecated library. And certainly the user never knows the difference.

But after sleeping on the idea i have decided to do it this way. This version of my script has 2.6.28 smarty which i believe is the last one before 3+.

I know there are some places where i do use the {php} and i know that has changed in 3+, so since I have made some template changes and i also have improved the performance of the script and have also now completed the conversion to mysqli library i think what i will do is release this version of my script as is. Then on the next version tackle the 3+ smarty.

This will allow me to focus on the smarty upgrade only and not have to worry about try to multi task so much and end up doing more harm than good.

The script is now back operational and working great, with a few more tweeks here and there ill release it and then start working on the smarty upgrade since that will be my only focus. I think doing it this way in stages is the smarter approach.

Thanks for the input i shall be back here at that time im sure if i have issues.

Smile have a great day
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jan 07, 2015 10:19 pm    Post subject: Reply with quote

If you really want to benefit from database interface change, switch to PDO.
Takes a little of reading and a little of practice, but then you can do many things with little effort.
Back to top
View user's profile Send private message
udirect61
Smarty n00b


Joined: 16 Jan 2015
Posts: 4

PostPosted: Fri Jan 16, 2015 5:29 am    Post subject: Reply with quote

What's the difference in PDO?
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