Mikepo Posted June 23, 2018 Share Posted June 23, 2018 Hi, Quick question, has anyone defined a hook for use in a nested module on the index page. i.e. cm_ip_product_listing.php? I can't seem to figure this out, as I get the following error: Fatal error: Uncaught Error: Call to a member function register() on null in D:\xampp70\htdocs\.....\includes\modules\product_listing.php: Adding a hook to product_info.php works ok, which doesn't have nested modules. any help please. Thanks Mike osC CE live - developing osC Phoenix adding modules with no core changes(awesome and easy!) Link to comment Share on other sites More sharing options...
♥kymation Posted June 25, 2018 Share Posted June 25, 2018 I don't know what your code looks like, but you may need to declare your hooks class as a global in the execute() method of the module that is calling product_listing.php. Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
Mikepo Posted June 26, 2018 Author Share Posted June 26, 2018 Hi Jim @kymation I still can't figure this out. (I'm using the CE frozen version) I'm limited with my code experience. I can create a hook (e.g. 'hello world' ) and insert it on the product_info.php page, but I can't add it the product_listing.php page. I register the hook in index.php using $OSCOM_Hooks->register('product'); and call the hook in product_listing.php page using $prod_list_contents .= $OSCOM_Hooks->call('product', 'hello_world'); the fatal error I get is: Fatal error: Uncaught Error: Call to a member function call() on null in D:\xampp70\htdocs\shopce\includes\modules\product_listing.php:116 Stack trace: #0 D:\xampp70\htdocs\shopce\includes\modules\content\index_products\cm_ip_product_listing.php(148): include() #1 D:\xampp70\htdocs\shopce\includes\classes\osc_template.php(146): cm_ip_product_listing->execute() #2 D:\xampp70\htdocs\shopce\index.php(60): oscTemplate->getContent('index_products') #3 {main} thrown in D:\xampp70\htdocs\shopce\includes\modules\product_listing.php on line 116 So where next. I assume because the index page has nested modules this error occurs, but I don't understand how the nested modules work. The product_info.php page is a straight forward single page and registering and calling the hook in the same file I understand. So can anyone advise please. Thanks Mike osC CE live - developing osC Phoenix adding modules with no core changes(awesome and easy!) Link to comment Share on other sites More sharing options...
♥kymation Posted June 26, 2018 Share Posted June 26, 2018 The problem here is that product_listing.php is not a page, it's only part of a page. It gets included into various modules, such as includes/modules/content/index_products/cm_ip_product_listing.php. Since it is an include, it acts like a part of the module class, and any variables you use need to be pulled into the appropriate class method. So to make it work in includes/modules/content/index_products/cm_ip_product_listing.php you need to add global $OSCOM_Hooks; into the execute() method of that file. You will need to do the same to the other modules that call product_listing.php or you will also get errors on the pages that use those modules. Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
burt Posted June 26, 2018 Share Posted June 26, 2018 As Jim @kymation rightly points out, it is complaing that you are using something that you don't have the "right" to use. To give yourself the right, you need to do exactly as Jim suggests and globalise the OSCOM-hook call. Link to comment Share on other sites More sharing options...
Mikepo Posted June 27, 2018 Author Share Posted June 27, 2018 @kymation@burt Thank you for your help. I just couldn't get my head round the problem even after you told me the solution. Leaving the screen and walking away for the night and it seems so obvious now. Thanks again! Mike osC CE live - developing osC Phoenix adding modules with no core changes(awesome and easy!) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.