bernhard Posted August 21, 2022 Share Posted August 21, 2022 1 hour ago, fruid said: I guess it gets intialised 3 times here because I call upon the module 3 times with wire('modules')->get('asdf'); You guess correctly. 1 hour ago, fruid said: The hook fires perfectly fine inside my site/ready.php file and everything works as intended, but not inside the ready() function inside my module it doesn't. The init() and ready() methods of a module can only correctly fire on "init" and "ready" if the module is either an autoload module or you load your module early enough in the ProcessWire boot process. If you load your module the very first time in a template file, then you are already in the Page::render() process, so you can't attach a hook to Page::render() since that has already been triggered! Does that make sense? Your module's init() method is called at the moment when you load your module via $modules->get(). That means it looks as if it works properly, but it actually fires a lot later than the autoload ready() and init(). You can check that by adding bd('site/ready.php') in /site/ready.php and the same in /site/init.php; You should see output like this: site/init.php site/ready.php --- Page::render() happens here --- your module's init your module's ready If you change your module to an autoload module (as the docs that you have read suggest ? ) the output should look like this: site/init.php your module's init site/ready.php your module's ready --- Page::render() happens here --- That means the hook that you attach in your module's init() or ready() will be available when the Page::render() is triggered and the hook should fire properly. Link to comment Share on other sites More sharing options...
froot Posted August 21, 2022 Share Posted August 21, 2022 if I add bd('site/ready.php'); to my ready.php file andbd('site/init.php'); to my init.php file It seems to load:site/ready module init site/init is the order legit? I fire some of the module's methods on the _main.php and like I said, I use markup regions, I guess that makes all the difference(?) And I need to load some of the module's methods when the page renders because these methods generate the markup… So if I change the module to autoload => true, do the module's ready() and init() functions fire exactly after the site's ready.php and init.php files load accordingly? Anyways, autoloading it doesn't help. 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