View previous topic :: View next topic |
Author |
Message |
rsinisa Smarty Rookie
Joined: 09 Oct 2017 Posts: 5
|
Posted: Mon Oct 09, 2017 6:45 am Post subject: Fatal error: Call to a member function _callExternalMethod() |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Oct 09, 2017 7:03 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Oct 09, 2017 1:29 pm Post subject: |
|
|
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 |
|
rsinisa Smarty Rookie
Joined: 09 Oct 2017 Posts: 5
|
Posted: Thu Oct 12, 2017 11:00 am Post subject: |
|
|
@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 |
|
rsinisa Smarty Rookie
Joined: 09 Oct 2017 Posts: 5
|
Posted: Thu Oct 12, 2017 11:11 am Post subject: |
|
|
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 |
|
rsinisa Smarty Rookie
Joined: 09 Oct 2017 Posts: 5
|
Posted: Thu Oct 12, 2017 11:54 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Oct 12, 2017 2:40 pm Post subject: |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Oct 12, 2017 5:05 pm Post subject: |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Oct 12, 2017 5:24 pm Post subject: |
|
|
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 |
|
rsinisa Smarty Rookie
Joined: 09 Oct 2017 Posts: 5
|
Posted: Thu Oct 12, 2017 7:43 pm Post subject: |
|
|
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 |
|
|