Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Fatal error: Call to a member function _callExternalMethod()

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
rsinisa
Smarty Rookie


Joined: 09 Oct 2017
Posts: 5

PostPosted: Mon Oct 09, 2017 6:45 am    Post subject: Fatal error: Call to a member function _callExternalMethod() Reply with quote

Hi to everyone.
I am programmer for long time (mostly INFORMIX), but I am new to PHP and all this web programming.
I found book "Beginning PHP and MYSQL e-commerce 2nd edition" and I want to learn some PHP and build web shop, so I use code from this book.
But this book is from 2008. and I suppose that smarty had some changes in code from that time.
So, I do everything as written in this book, and after first test I get this fatal error:

Fatal error: Call to a member function _callExternalMethod() on null in /home/sinisa/.lmmf/tshirtshop/libs/smarty/sysplugins/smarty_internal_data.php on line 241

Can somebody help me to overcome this first problem?

Thanks in advance
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 120
Location: West Coast

PostPosted: Mon Oct 09, 2017 7:03 am    Post subject: Reply with quote

You should test if Smarty can be instantiated without problems.

Just after you instantiate the Smarty class (first line), add the test statement (second line):
Code:
$smarty  = new Smarty();
$smarty->testInstall();
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1105

PostPosted: Mon Oct 09, 2017 1:29 pm    Post subject: Reply with quote

Writing a web shop from scratch is not a very good idea.
Get a known trusted solution and modify it to your needs.

Regarding your Smarty question, please show some code to illustrate your issue.
Back to top
View user's profile Send private message
rsinisa
Smarty Rookie


Joined: 09 Oct 2017
Posts: 5

PostPosted: Thu Oct 12, 2017 11:00 am    Post subject: Reply with quote

@bsmither
Thank you for reply, I tried this and get some info.
But, let's go first from index.php:
Code:
<?php
// Include utility files
require_once 'include/config.php';
// Load the application page template
require_once PRESENTATION_DIR . 'application.php';
// Load Smarty template file
$application = new Application();
// Display the page
$application->display('store_front.tpl');
?>

First line includes config.php. This is config.php:
Code:
<?php
// SITE_ROOT contains the full path to the tshirtshop folder
define('SITE_ROOT', dirname(dirname(__FILE__)));
// Application directories
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/');
define('BUSINESS_DIR', SITE_ROOT . '/business/');
// Settings needed to configure the Smarty template engine
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/');
define('TEMPLATE_DIR', PRESENTATION_DIR . 'templates');
define('COMPILE_DIR', PRESENTATION_DIR . 'templates_c');
define('CONFIG_DIR', SITE_ROOT . '/include/configs');
?>

It changes required directories path, but when I add your two lines in index.php just before line,
Code:
$application = new Application();

I get this:
Code:
Smarty Installation test...
Testing template directory...
FAILED: /home/sinisa/.lmmf/tshirtshop/templates/ does not exist.
Testing compile directory...
FAILED: /home/sinisa/.lmmf/tshirtshop/templates_c/ does not exist.
Testing plugins directory...
/home/sinisa/.lmmf/tshirtshop/libs/smarty/plugins is OK.
Testing cache directory...
/home/sinisa/.lmmf/tshirtshop/cache is OK.
Testing configs directory...
FAILED: /home/sinisa/.lmmf/tshirtshop/configs/ is not a directory.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.

Fatal error: Call to a member function _callExternalMethod() on null in /home/sinisa/.lmmf/tshirtshop/libs/smarty/sysplugins/smarty_internal_data.php on line 241

So, I still think that book is too old for this new version of smarty. Am i right?

Best regards
Back to top
View user's profile Send private message
rsinisa
Smarty Rookie


Joined: 09 Oct 2017
Posts: 5

PostPosted: Thu Oct 12, 2017 11:11 am    Post subject: Reply with quote

AnrDaemon wrote:
Writing a web shop from scratch is not a very good idea.
Get a known trusted solution and modify it to your needs.

Yes, I agree with You, but:
1. I tried some trusted solutions and I am not satisfied 100%.
2. From my 35 years programming experience I know that changing others code can be very very difficult and time consuming.
3. This is not writing from scratch, this is copy/paste code from book, and it is also trusted solution, but maybe book is too old.
4. I want to learn something new and have plenty time for this because it is not something that I MUST do, I just want to do that for fun.
5. I want to learn smarty and I think that this book offers me to learn few things at same time.

Thank you for your reply.
Best regards.


Last edited by rsinisa on Thu Oct 12, 2017 12:12 pm; edited 1 time in total
Back to top
View user's profile Send private message
rsinisa
Smarty Rookie


Joined: 09 Oct 2017
Posts: 5

PostPosted: Thu Oct 12, 2017 11:54 am    Post subject: Reply with quote

I forgot to put application.php file:
Code:
<?php
// Reference Smarty library
require_once SMARTY_DIR . 'Smarty.class.php';
/* Class that extends Smarty, used to process and display Smarty
files */
class Application extends Smarty
{
// Class constructor
public function __construct()
{
// Call Smarty's constructor
parent::Smarty();
// Change the default template directories
$this->template_dir = TEMPLATE_DIR;
$this->compile_dir = COMPILE_DIR;
$this->config_dir = CONFIG_DIR;
}
}
?>
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1105

PostPosted: Thu Oct 12, 2017 2:40 pm    Post subject: Reply with quote

Do not redefine SMARTY_DIR.
Or even better, use Composer to install Smarty and any other libs you may wish to use.
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 120
Location: West Coast

PostPosted: Thu Oct 12, 2017 5:05 pm    Post subject: Reply with quote

If you are running your own server, or can program additional code into this application, I suggest:
* installing the XDebug PHP extension, or
* adding your own error_handler()

Either will give you the means to have PHP show you the path of execution as an array that will show what PHP statement eventually caused the Fatal Error in the Smarty code.

The _callExternalMethod() on null doesn't explain much if we do not know what called it.
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 120
Location: West Coast

PostPosted: Thu Oct 12, 2017 5:24 pm    Post subject: Reply with quote

It could be the case that the code in the tutorial is "too old".

The current docs say that:
Code:
$this->template_dir = TEMPLATE_DIR;
is no longer valid. Direct access to these class attributes is no longer allowed. This syntax is needed:
Code:
$this->setTemplateDir(TEMPLATE_DIR);
or, perhaps better (depending on your in-house style-guide for program code):
Code:
$application = new Application();
$application->setTemplateDir(TEMPLATE_DIR);
$application->setCompileDir(COMPILE_DIR);
$application->setConfigDir(CONFIG_DIR);
$application->setCacheDir(CACHE_DIR);
Back to top
View user's profile Send private message
rsinisa
Smarty Rookie


Joined: 09 Oct 2017
Posts: 5

PostPosted: Thu Oct 12, 2017 7:43 pm    Post subject: Reply with quote

bsmither wrote:
It could be the case that the code in the tutorial is "too old".

I suspected that this is the case. OK, thank you, I will probably leave this book for now and search for newer.

Best regards.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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