Jump to content

with json encode, module not validating in validator


Recommended Posts

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

  On 3/13/2014 at 11:01 AM, prestashop_newuser said:

 

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

  On 3/13/2014 at 5:37 PM, Yopixel said:
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

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.

  • Like 1
Link to comment
Share on other sites

  On 3/13/2014 at 6:52 PM, Vinum said:

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

  On 3/14/2014 at 9:19 AM, prestashop_newuser said:

@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

  • 5 months later...
  • 2 years later...
×
×
  • Create New...