Welcome Guest, Not a member yet? Register   Sign In
pre_system hook
#1

[eluser]jonyr[/eluser]
Hi everybody, congratulations for this excellent forum. There are here very interesting information.
I'm very new in codeigniter, so I reading a lot because I love this framework.
I have the next question:

Scenario:

---- /application/config/config.php -----
$config['enable_hooks'] = TRUE;

---- /application/config/hooks.php ----
$hook['pre_controller'] = array(
'class' => 'my_cache',
'function' => 'pre_cache',
'filename' => 'my_cache_hook.php',
'filepath' => 'hooks'
);

How many times this function (pre_cache) will be executed, if I call this url http://mydomain.com/index.php/welcome/index ? (It is the default controller)

To check this, in the constructor of my_cache class, I'm creating a file with a random name using file_put_contents. Something like this
-----------------------------------------------------------
$file_name = microtime(true) . ".temp";
file_put_contents($some_path . $file_name, microtime(true);
-----------------------------------------------------------

I am a bit confuse, Why two of this files are created?

Could anyone help me to understand this?

Thanks in advance.

JonyR
#2

[eluser]tomcode[/eluser]
Welcome JonyR,

Just some remarks :

You can enable logging in application/config/config.php.

Add log messages in the places You're interested in, see User Guide, Errors.

CI comes has some caching methods.

I would not use the prefix my_ for naming, MY_ is by default used to extend CI.

You're hook constructor should run only once.
#3

[eluser]jonyr[/eluser]
Hey Tomcode! Thanks for your answer.
I really aprecciate it.

1 - Thanks for remember the logging.
2 - You're right I rename my hook class from my_cache to smart_cache
3 - For some reason, that I could not detect pre_system is launched two times.

The new scenario is
-------------------
——/application/config/config.php——-
$config[‘enable_hooks’] = TRUE;
$config['log_threshold'] = 2;

——/application/config/hooks.php——

My hook configuration is

$hook['pre_system'][] = array(
'class' => 'site_offline_hook',
'function' => 'is_offline',
'filename' => 'site_offline_hook.php',
'filepath' => 'hooks'
);

$hook['pre_system'][] = array(
'class' => 'smart_cache',
'function' => 'pre_cache',
'filename' => 'smart_cache_hook.php',
'filepath' => 'hooks'
);

$hook['post_system'] = array(
'class' => 'smart_cache',
'function' => 'post_cache',
'filename' => 'smart_cache_hook.php',
'filepath' => 'hooks'
);


Right now, I'm using logg_message as you recomended me.

public function pre_cache()
{
log_message('debug','smart_cache pre_cache function');
}

public function pre_cache()
{
log_message('debug','smart_cache post_cache function');
}

----------------------------------------------------------------
Later of this, I ask for http://mydomain.com/index.php/welcome/index and see into my log file

DEBUG - 2010-02-20 00:45:19 --> smart_cache pre_cache function
DEBUG - 2010-02-20 00:45:20 --> smart_cache post_cache function
DEBUG - 2010-02-20 00:45:20 --> smart_cache pre_cache function

¿What am I doing wrong?

Thanks in advance,
JonyR
#4

[eluser]jonyr[/eluser]
Hey Tomcode, me again.
I put the $_SERVER["REQUEST_URI"] at the end of my logg_message and...

DEBUG - 2010-02-20 01:02:21 --> smart_cache pre_cache function/welcome
DEBUG - 2010-02-20 01:02:22 --> smart_cache post_cache function/welcome
DEBUG - 2010-02-20 01:02:22 --> smart_cache pre_cache function/favicon.ico

¿What can you say me about that?

Thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB