PHP5 and smarty configuration problems - php

I was reading Beginning PHP and MySQL ecommerce. The author asks to download latest smarty version.When book was published it was smarty 2.x now its 3.x.
I copied all the files from code download to my folder. The error i got was
Fatal error: Uncaught exception 'SmartyException' with message 'PHP5 requires you to call __construct() instead of Smarty()'
To correct it i changed my code to
<?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::__construct();
// Change the default template directories
$this->template_dir = TEMPLATE_DIR;
$this->compile_dir = COMPILE_DIR;
$this->config_dir = CONFIG_DIR;
}
}
?>
I've follow the following links
Fatal error: Uncaught exception 'SmartyException'
Then I got this error:
ERRNO: 2 TEXT: filemtime(): stat failed for
C:\xampp\htdocs\tshirtshop/presentation/templates_c\b34e4db7de306d57170626b504196f0c5fe34fa4.file.store_front.tpl.php
LOCATION:
C:\xampp\htdocs\tshirtshop\libs\smarty\sysplugins\smarty_resource.php,
line 772, at August 22, 2014, 9:59 am Showing backtrace:
filemtime("C:\xampp\htdocs\tshirtshop/presentation/templates_c\b34e4db7de30...")
line 772, file: C:\xampp\htdocs\tshirtshop\libs\smarty\sysplugins\smarty_resource.php
Smarty_Template_Source.getCompiled(Object: Smarty_Internal_Template) #
line 699, file:
C:\xampp\htdocs\tshirtshop\libs\smarty\sysplugins\smarty_internal_template.php
Smarty_Internal_Template.__get("compiled") # line 154, file:
C:\xampp\htdocs\tshirtshop\libs\smarty\sysplugins\smarty_internal_templatebase.php
Smarty_Internal_TemplateBase.fetch("store_front.tpl", null, null,
null, true) # line 394, file:
C:\xampp\htdocs\tshirtshop\libs\smarty\sysplugins\smarty_internal_templatebase.php
Smarty_Internal_TemplateBase.display("store_front.tpl") # line 16,
file: C:\xampp\htdocs\tshirtshop\index.php

Your PHP code looks fine.
You should clear your compiled templates directory, check your directory/files permissions and if it doesn't help, in fact you shouldn't care. Those warnings are because of some file system operations optimization.
If you want to turn them off you can use:
$this->muteExpectedErrors();
inside your constructor (probably after calling parent constructor). Documentation on muteExpectedErrors

Related

Uncaught Error: Class 'Document' not found

I want to divide the code I have written into smaller manageable files. One file has over 2500 lines and I think it might be better to put some of its code into a separate header file. However, as soon as I separate the code and run it. I get the following error:
Uncaught Error: Class 'Document' not found
Here is the code of my large-file.php:
<?php
require_once("common-head.php");
/* Some more code */
$document = new Document($document_html);
Here is the code of my common-head.php:
<?php
/* Some code */
require_once('vendor/autoload.php');
use DiDom\Document;
/* Some more code */
Both the files are located in the same directory so the path to vendor/autoload.php does not change. However, if the code is placed in separate files as I have shown above, I get the error:
Uncaught Error: Class 'Document' not found
If I take all the code out of common-head.php and place it in my large-file.php in place of require_once("common-head.php");. It works without any error. How can I resolve this issue?
Just using use in same file.
// large-file.php
use DiDom\Document;
require_once("common-head.php");
/* Some more code */
$document = new Document($document_html);
see - PHP namespaces and "use"

whenever using database library,error message is displayed

whenever loading this
$this->load->library('database');
error is shown
Unable to load the requested class: database
without the above mentioned code,the following error is shown.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: LoginPage::$db
Filename: core/Model.php
Line Number: 52
Fatal error: Call to a member function select() on null in
C:\xampp\htdocs\Test_LR\application\models\Login_model.php on line 11
FIle permission From Filezilla...
Connect your FTP client to your web server. In FileZilla, right-click the "system" folder on your web server and choose File Permissions to open the file attributes. Type the correct number in the Numeric Value text field
This means CodeIgniter has a library database.
You can include libraries in two ways:
1) In application/config/autoload.php
Code:
$autoload['libraries'] = array('database'); // Include other libraries here like `session`.
2) Run time by using $this->load->library('database'); if not included with first method.
Without it, it will show fatal error.
Have you tried to use:
$this->load->database();
Instead of $this->load->library('database');
Or double check if your database file available on system
Sample example Usersmodel.php
class usersmodel extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function examplefunction()
{
}
}

Smarty error: Call to a member function get_articlelist_primary() on a non-object

I am forced to use Smarty for a project but the server is running slow, so I tried to work with it locally on MAMP.
I am a complete beginner when it comes to Smarty.
First I downloaded smarty then in index.php for the site I am making, I made a class:
class Panel{
public function __construct__(){}
public function get_articlelist_primary(){return array();}
}
Then I made an instance:
$panelObj=new Panel();
Did my thing with Smarty:
require_once("../Smarty-3.1.20/libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = 'views';
$smarty->compile_dir = 'tmp';
$smarty->assign("panelObj",$panelObj);
$smarty->display("index.tpl");
Then I made a template, and it dosen't work. The PHP error log says:
[17-Oct-2014 20:48:38 Europe/Berlin] PHP Fatal error: Call to a member function get_articlelist_primary() on a non-object in /Applications/MAMP/htdocs/LanderTemplate/tmp/3dd4ab168909a8c2acf37974fa4b15c661cc2857.file.index.tpl.php on line 377
Line 377 in the compiled template is:
if (count($_smarty_tpl->tpl_vars['panelObj']->value->get_articlelist_primary())) {?></div><?php }?>
Wrote this line in the compiled template to error log it:
<?php error_log(print_r($_smarty_tpl->tpl_vars['panelObj'],1));
It returned:
[17-Oct-2014 20:48:38 Europe/Berlin] Smarty_Variable Object
(
[value] =>
[nocache] =>
[scope] => 0
[_loop] =>
)
It seems that "value" should be equal to the instance since I had assigned it, but it is just blank. What could be the reason for this? I'm using Smarty 3.1.20.
You should make sure you are doing everything fine so please try this code to make sure you have $panelObj defined in current scope.
class Panel{
public function __construct(){}
public function get_articlelist_primary(){return array();}
}
$panelObj=new Panel();
var_dump($panelObj);
$smarty->assign("panelObj",$panelObj);
$smarty->display("index.tpl");
And in index.tpl file:
{$panelObj->get_articlelist_primary()}
If you have error_reporting enabled, you will see only notice:
object(Panel)#17 (0) { }
Notice: Array to string conversion in ...\templates_c\6a7a7402e26bab6fe66fe3d214cc5fb929376cc9.file.sb.tpl.php on line 34
Array
because you return array in this function, but as you see this class method can be launched without any problem. I've tested it in 3.1.19 version

SmartyBC (Backwards Compatibility Wrapper) doesn't work in PrestaShop

As adviced in Smarty's instruction, in order to use deprecated functions like include_php in newest PrestaShop, I had to switch from Smarty.class.php to SmartyBC.class.php. I did it by modyfing in smarty.config.inc.php following lines:
require_once(_PS_SMARTY_DIR_.'SmartyBC.class.php');
// require_once(_PS_SMARTY_DIR_.'Smarty.class.php');
global $smarty;
// $smarty = new Smarty();
$smarty = new SmartyBC();
However, using {include_php file='./custom_php/manufacturers.php'} in theme's header.tpl still results in blank screen. Errors from php_error_log :
[22-Jul-2014 15:05:55 Europe/Warsaw] PHP Notice: Undefined property: SmartyBC::$trusted_dir in C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\Smarty.class.php on line 676
[22-Jul-2014 15:05:55 Europe/Warsaw] PHP Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\themes\trzmiel\header.tpl" on line 101 "{include_php file='./custom_php/manufacturers.php'}" {include_php} file './custom_php/manufacturers.php' is not readable' in C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php:667
Stack trace:
#0 C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\sysplugins\smarty_internal_compile_include_php.php(81): Smarty_Internal_TemplateCompilerBase->trigger_template_error('{include_php} f...', 101)
#1 C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php(485): Smarty_Internal_Compile_Include_Php->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL)
#2 C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\sysplugins\smarty_internal_templ in C:\BACKUP\Dropbox\!_PC\LOCALHOST\_INTERCLICK\trzmiel5\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 667
It seems that trusted_dir property is available only when using Security Policy:
class My_Security_Policy extends Smarty_Security {
public $trusted_dir = './custom_php/';
}
$smarty = new SmartyBC();
// enable security
$smartyBC->enableSecurity('My_Security_Policy');
so you should provide here correct path (I don't know is it relative or not - you should give a try) and then you should be able to use manufacturers.php file in your template file but you should also here look at correct file path.

Fatal error: Call to undefined method Zend_XmlRpc_Value::getGenerator() magento

I was upgrading magento when something went wrong and now when I try to login to admin, I am unable to log in to back end admin of magento and I get the following error
Fatal error: Call to undefined method Zend_XmlRpc_Value::getGenerator() in /home/boutique/public_html/app/code/core/Zend/XmlRpc/Request.php on line 413
and the code on respective lines is
/**
* Create XML request
*
* #return string
*/
public function saveXml()
{
$args = $this->_getXmlRpcParams();
$method = $this->getMethod();
$generator = Zend_XmlRpc_Value::getGenerator();
$generator->openElement('methodCall')
->openElement('methodName', $method)
->closeElement('methodName');
I cant understand why this issue is happening, I tried replacing request.php and response.php files from fresh download of magento..
can body help me? why this eror is popping?
There's something about your installation of PHP and Magento that's broken — for some reason the Zend_XmlRpc_Value object that's instantiated doesn't contain a getGenerator method. The class for this object is normally defined in
lib/Zend/XmlRpc/Value.php
However, it's possible there may be a class override in place at
app/code/core/Zend/XmlRpc/Value.php
app/code/community/Zend/XmlRpc/Value.php
app/code/local/Zend/XmlRpc/Value.php
It's also possible your system may have another version of the zend framework installed somewhere in the PHP include path.

Categories