Welcome Guest, Not a member yet? Register   Sign In
Making a helper/plugin
#1

[eluser]Maglok[/eluser]
I have been working on getting the SMF forum to work with my CI application.

They have a file called SSI.php that I end up including everywhere. If I can just 'wrap' that somehow in a helper or plugin (plugin is proper I think?) so I can autoload it, that would be sweet.

The user_guide doesnt really have a explanation of how to make a plugin, anyone can point me in the right direction?
#2

[eluser]xwero[/eluser]
the content of a helper/plugin are just functions. the only difference is that a plugin holds one function where a helper holds several.
#3

[eluser]kalebheitzman[/eluser]
Hey Simon,

Can you load it as a library file and then autoload it? You can then call your functions like $this->ssi->ssi_welcome() for example. This is what I've done with the Textile.php file for the textile wysiwyg.
#4

[eluser]Maglok[/eluser]
Aren't libraries part of the core, as described in the user_guide?

The problem here is that SSI.php needs to be in the forum root, not in the helper dir of CI.

@Xwero: Is it hardcoded plugins can only have one?
#5

[eluser]xwero[/eluser]
The libraries in the system directory could be seen as the core libraries because that is where the core libraries are but there are not going to be problems if you add a library of your own. My rule is if the library is used in multiple apps put it in the system directory else put it in the application directory.

No plugins are not hard coded to contain a single function but if you add more functions then you wipe out the difference between plugins and helpers. I don't say you shouldn't do it, it's just a matter of preference.

The technical difference between plugins and helpers is the directory where they are stored, the plugin has to have a _pi.php extension and the helper can be extended.
#6

[eluser]Maglok[/eluser]
So a library for SSI.php would probably have to require_once the SSI.php (which is going to be located outside of CI). I guess it's one place, but it isn't really good to have to edit a library with a path.

Also it would probably 'just' entail 'remapping' the functions in the SSI.php. Like if SSI.php has a ssi_logout() I'd have to make a function like:

Code:
function smf_logout($redirect) {
    ssi_logout($redirect);
}

There has to be a easier way to do this.
#7

[eluser]Michael Wales[/eluser]
1. Place a symlink in your application/libraries/ directory pointing to SSI.php wherever it is.
2. Load it as a library from within CodeIgniter.
3. Profit!
#8

[eluser]Maglok[/eluser]
...Hmmm, yeah you got a point there Smile Gonna try that out. Sometimes easier is better.
#9

[eluser]Maglok[/eluser]
Yeah you can't do that cause SSI.php also uses paths. It will execute as if from the library dir, thus fail. Smells like I need to make a wrapper class still.
#10

[eluser]R. Oerlemans[/eluser]
You can use $config['base_url']




Theme © iAndrew 2016 - Forum software by © MyBB