prestashop_newuser Posted March 13, 2014 Share Posted March 13, 2014 Hi, I am doing a small module in Prestashop 1.5 . In that module I am getting some data from database as json format. For that I have done this echo json_encode(array($result)); This one is working fine. But when I tried to upload the module to prestashop validator, it showed me the error like The use of function json_encode() is forbidden; use Tools::jsonEncode() instead But when I tried echo Tools::json_encode(array($result)) it showed the error like Fatal error: Call to undefined method Tools::json_encode(). So can someone kindly tell me how to solve this issue. any help and suggestions will be really appreciable. Thanks Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 13, 2014 Author Share Posted March 13, 2014 Hi, I am doing a small module in Prestashop 1.5 . In that module I am getting some data from database as json format. For that I have done this echo json_encode(array($result)); This one is working fine. But when I tried to upload the module to prestashop validator, it showed me the error like The use of function json_encode() is forbidden; use Tools::jsonEncode() instead But when I tried echo Tools::json_encode(array($result)) it showed the error like Fatal error: Call to undefined method Tools::json_encode(). So can someone kindly tell me how to solve this issue. any help and suggestions will be really appreciable. Thanks Is there any one who can solve this? Link to comment Share on other sites More sharing options...
YopixelAE Posted March 13, 2014 Share Posted March 13, 2014 Hi, Does your php file extend the Module class ? Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 13, 2014 Author Share Posted March 13, 2014 Hi, Does your php file extend the Module class ? Nope...I have used that in another php file but not extended the module class. Can you tell me how to extend that? As I am newbie in prestashop module. Link to comment Share on other sites More sharing options...
YopixelAE Posted March 13, 2014 Share Posted March 13, 2014 (edited) class YourModule extends Module { public function assignWhatyouWant() { //...your process $my_results = Tools::json_encode(array($result)); //... $this->smarty->assign(array(//...)); } } You should have something like that. Edited March 13, 2014 by Yopixel (see edit history) Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 13, 2014 Author Share Posted March 13, 2014 class YourModule extends Module { public function assignWhatyouWant() { //...your process $my_results = Tools::json_encode(array($result)); //... $this->smarty->assign(array(//...)); } } You should have something like that. I have used json_encode not in module file. I have used that in another php file.In template smarty tpl file I have used ajax and in the url file that one is an another php file. In tha file I have used json_encode. So how to use Tools::json_encode in another file Link to comment Share on other sites More sharing options...
Vinum Posted March 13, 2014 Share Posted March 13, 2014 Hi, Add that in the head of your file : include ('../../config/config.inc.php'); include ('../../init.php'); Perhaps the init.php is not necessary. The path to the config.inc.php and init.php have to be updated with your config. 1 Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 14, 2014 Author Share Posted March 14, 2014 Hi, Add that in the head of your file : include ('../../config/config.inc.php'); include ('../../init.php'); Perhaps the init.php is not necessary. The path to the config.inc.php and init.php have to be updated with your config. @Vinum thanks for the reply..well when I included include ('../../config/config.inc.php'); and tried echo Tools::json_encode(array($result)); then it showed me error like Fatal error: Call to undefined method Tools::json_encode() but if I am using only echo json_encode(array($result)); then it is not showing any error. But as per prestashop standard I have to use Tools. So can you tell me why it is showing error and how to solve this? Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 18, 2014 Author Share Posted March 18, 2014 @Vinum thanks for the reply..well when I included include ('../../config/config.inc.php'); and tried echo Tools::json_encode(array($result)); then it showed me error like Fatal error: Call to undefined method Tools::json_encode() but if I am using only echo json_encode(array($result)); then it is not showing any error. But as per prestashop standard I have to use Tools. So can you tell me why it is showing error and how to solve this? Is there anyone who can solve my problem? Link to comment Share on other sites More sharing options...
AperoCD Posted August 28, 2014 Share Posted August 28, 2014 It looks like you're mistyping the function name. It's Tools::jsonEncode() and not Tools::json_ecode() 1 Link to comment Share on other sites More sharing options...
bellini13 Posted August 28, 2014 Share Posted August 28, 2014 it is not difficult to open the Tools.php file in the classes folder and confirm the name of the function exists Link to comment Share on other sites More sharing options...
sasaaa23 Posted November 26, 2016 Share Posted November 26, 2016 Just use Tools::jsonEncode as said in the message. The name Tools::json_decode is not recognised Link to comment Share on other sites More sharing options...
Recommended Posts