democolis Posted June 23, 2015 Share Posted June 23, 2015 Hi, I have create a custom module. At this time my module do the job i want to do but i use a cronjob to run a php file every 1 minute. How can i run the specifi php file every time where my page loads instead of cronjob? I try to include the php code in a tpl file with {php} content {/php} but it fails..Any Ideas Please?? Thanks a lot! Link to comment Share on other sites More sharing options...
Oexo France Posted June 23, 2015 Share Posted June 23, 2015 Hi, What dont you do an ajax call with a setinterval? Regards Link to comment Share on other sites More sharing options...
democolis Posted June 23, 2015 Author Share Posted June 23, 2015 mmm..i don't know exactly how to do it..my php file is written in clean PHP (not smarty)..Is there any problem with that if i use your method? Is there other way to do it (without the ajax)?? Thanks a lot! Link to comment Share on other sites More sharing options...
Oexo France Posted June 23, 2015 Share Posted June 23, 2015 Call your php file with js inside your tpl file it's simply as this Link to comment Share on other sites More sharing options...
democolis Posted June 23, 2015 Author Share Posted June 23, 2015 yes, i try this but it failed..what's the correct code to do that? lets say tha we have a file called "test.php" what's the correct code to execute it? Thanks a lot! Link to comment Share on other sites More sharing options...
vekia Posted June 23, 2015 Share Posted June 23, 2015 if you want to run something everytime page will be loaded, just associate module with displayHeader hook and in public function displayHeader() add code that you want to run when page will be loaded.public function displayHeader(){ // code to run here } ps. don't forget to registerHook('displayHeader'); Link to comment Share on other sites More sharing options...
democolis Posted June 23, 2015 Author Share Posted June 23, 2015 Vekia in this function you mention is needed to write my code in smarty right? i use clean php..is this a problem or is it accepted? Thanks! Link to comment Share on other sites More sharing options...
vekia Posted June 23, 2015 Share Posted June 23, 2015 hello let's clarify something :-) you said that you created module so by module i understand "prestashop module" that you install under modules > modules section. if you use it (prestashop module) you can run some codes during page generation process, for example - in displayHeader hook. like it is described here: http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Implementinghooks 1 Link to comment Share on other sites More sharing options...
democolis Posted June 23, 2015 Author Share Posted June 23, 2015 vekia of course its a prestashop module..i have install it and everything is ok but i have a php file in my module's folder which i run with a cronjob. this file is written in clean php so the prestashop with the smarty engine gives me error when i try to insert my clean php file in a function. this is the most necessary file because i use it to check the most stuff and i am try to find a way to execute it without error and of course without cronjob. The basic problem is that my file is WRITTEN IN CLEAN PHP. I wish you can help. Thanks a lot! Link to comment Share on other sites More sharing options...
vekia Posted June 23, 2015 Share Posted June 23, 2015 why not to add this code (from your separate php file) to displayHeader() function inside your module file? Link to comment Share on other sites More sharing options...
Oexo France Posted June 23, 2015 Share Posted June 23, 2015 assign a smarty variable to your prestashop code. You have two solutions: - You register a hook that load a js file, the js file call the php via ajax request. - You crate a private function and load paste the code on, you assign this to an hook and its ok. Link to comment Share on other sites More sharing options...
democolis Posted June 23, 2015 Author Share Posted June 23, 2015 it gives error..i have commands like fopen,fclose and more that is not supported i guess in the modules function.. Link to comment Share on other sites More sharing options...
vekia Posted June 23, 2015 Share Posted June 23, 2015 modules support all functions that are available in your php. if you will want to sell it on addons store - module will not be validated positively and that is the only one reasony to not use fopen etc. in module file. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now