Welcome Guest, Not a member yet? Register   Sign In
Correct Way to Call Hooks Functions?
#1

[eluser]Vik[/eluser]
I've added hooks for Simple Machines Forums to my CI installation, using code provided here by DanFreak:

[quote author="danfreak" date="1175743689"]
application/config.php
Code:
$config['enable_hooks'] = TRUE;

application/config/hooks.php
Code:
$hook['post_controller_constructor'] = array(
                                'class'    => '',
                                'function' => 'load_ssi_smf',
                                'filename' => 'ssi.php',
                                'filepath' => 'hooks'
                                );

application/hooks/ssi.php

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
function load_ssi_smf()
{
        require_once('smf/SSI.php'); //change the directory to suit your needs
}
?>
[/quote]

My question is, how do I call a function from ssi.php? For example, I've tried:
Code:
$UserIsLoggedIn = smf_authenticateUser();

...and found that this generates an “undefined function” error.

What is the correct way to do this?

Thanks very much in advance for any info.
#2

[eluser]gtech[/eluser]
ignore this reply, I realized I was talking rubbish
#3

[eluser]gtech[/eluser]
[url=http://ellislab.com/forums/viewthread/61705/"](Look at this thread) [/url]and beatryders reply. He posted piece of code that will suit your needs I think. he uses a class in the hook and in the constructer points to the instance of the CodeIgniter Object
Code:
$this->CI =& get_instance();

then you can do things like
Code:
$CI->load->library('session');
$CI->load->helper('file');
etc
#4

[eluser]Phil Sturgeon[/eluser]
Now is that what you mean or are you asking if you can call a function defined in a hook but called elsewhere (controller, etc).

The short answer is the same answer used alot round here. "yes, but you shouldnt". You could directly include() the file then call it but thats a bit smelly. Id put the functions in a lib or model then call them anywhere you like.
#5

[eluser]Vik[/eluser]
Thanks for this feedback, guys.

I thought I was installing the hook correctly, because code execution got to my controller/index method without a hitch. But I just realized that since this is a 'post_controller_constructor', it seems to get installed after that point.

Now I'm getting this error when the hook is being installed:

Quote:Message: SSI.php was unable to load a session! This may cause problems with logout and other functions - please make sure SSI.php is included before *anything* else in all your scripts!

The error message is generated by this code in ssi.php:

Code:
// Make sure they didn't muss around with the settings... but only if it's not cli.
if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
    trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);

When that code runs, these are the contents of the variables it is looking at:

$_SERVER['REMOTE_ADDR'] contains 127.0.0.1.
$_SERVER['is_cli'] is not set.
session_id() == ''.

So at this point this has become more of a Simple Machines Forum question than a CI question. I'll check on the SMF forums for more info.

A lot of people would like to know how to tie a forum like SMF into their CI apps, so I'll post here if I find out how to do it.

Of course, if anyone reading this happens to have some info for me, please post it. Smile

DanFreak and others have accomplished it already, so it appears that it can be done.
#6

[eluser]MrPrise[/eluser]
I had exactly the same problem. After a while I found out SMF uses native PHP sessions while CI does not. I suspect that caused the issue. The warning gone when I changed the begining of my load_ssi_smf() in the ssi.php to the following:

Code:
function load_ssi_smf()
{
     global $CI;
     session_id($CI->session->userdata('session_id'));

Please someone who knows better both system confirm if that is a correct fix for that problem. It seems that is working, however I don't check everything yet.
#7

[eluser]Vik[/eluser]
Thanks for the info, MrPrise.

Do you use ssi.php and also smf.api, or just one or the other?

Can you register users on your site's home page, without sending them to the SMF registration page?
#8

[eluser]MrPrise[/eluser]
[quote author="Vik" date="1195274885"]Do you use ssi.php and also smf.api, or just one or the other?[/quote]
I just use ssi.php.

[quote author="Vik" date="1195274885"]Can you register users on your site's home page, without sending them to the SMF registration page?[/quote]
Well, I have not went this far yet ;-) I just started to play with CI a few days ago. My first goal was to use my SMF template (I mean the CSS and the header and footer so the generated pages will look similar no matter which system generate them) from my CI and show the login box to log into SMF from CI. I'm glad, because these are already working.

I'm not sure if we can continue to talk about SMF-CI integration in this topic.
If there is a topic for that we can continue to share our experiences there.
#9

[eluser]Vik[/eluser]
I have started a new thread, here.




Theme © iAndrew 2016 - Forum software by © MyBB