Renard Masque
Renard Masque

Reputation: 73

CodeIgniter 3 / Basic Hook Loading Problems

Hey I'm sure I miss something obvious, but can't figure out what it is : I can't get a simple hook working with my quasi blank installation of CI 3 ...

I've put the simplest of the code possible with a Hook called MyTest and it works fine :

application/config/hooks.php

$hook['post_controller_constructor'][] = array(
    'class'    => 'MyTest',
    'function' => 'TestMe',
    'filename' => 'MyTest.php',
    'filepath' => 'hooks',
    'params'  => ''
 );

application/hooks/MyTest.php

class MyTest{

     function TestMe()
     {
         die("die by the hook TEST");
     }

 }

->this outputs "die by the hook TEST", which is what is expected.

But almost the same with a Hook called URI_Actions doesn't work at all :

application/config/hooks.php

$hook['post_controller_constructor'][] = array(
    'class'    => 'URI_Actions',
    'function' => 'index',
    'filename' => 'URI_Actions.php',
    'filepath' => 'hooks',
    'params'  => ''
 );

application/hooks/URI_Actions.php

class URI_Actions{

     function index()
     {
         die("die by the hook URI Actions");
     }

 }

-> this doesn't output anything ... I'm sure I'm missing something enormous, any idea ?

Epilogue

Of course the problem was elsewhere : binary FTP transfert was the issue, once the files uploaded normally the same codes worked perfectly. Thanks to trajchevska which made me realize the code was not the problem !

Upvotes: 3

Views: 603

Answers (1)

trajchevska
trajchevska

Reputation: 952

Does it not display anything or it displays "die by the hook TEST" only? The thing is that you have them both defined one after the other and they're both doing dump and die. So when the Test hook displays the result, the program dies and doesn't get to the URI_Actions hook.

Try using a simple var_dump instead of die, you should get the expected result. I tested both locally and they work fine.

Upvotes: 1

Related Questions