Jump to content

Custom Module - Run On Page Load


democolis

Recommended Posts

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

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

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

  • Like 1
Link to comment
Share on other sites

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

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

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...