Welcome Guest, Not a member yet? Register   Sign In
CI helpers in EE templates
#1

[eluser]e-man[/eluser]
I've only just began to get my feet wet with CI and was wondering: if I have CI installed as well as EE can I use the CI helpers inside the EE templates?
In other words, can I just do:
Code:
$this->load->helper('name');
in an EE template?
#2

[eluser]Jamie Rumbelow[/eluser]
No. As of yet, EE and CI aren't linked. When EE 2.0 comes however, I'm going to assume there will be a EE tag such as this:

Code:
{exp:codeigniter:helper="name"}
#3

[eluser]e-man[/eluser]
Would be cool, those helpers contain a lot of cool functionality Smile
I'll keep my eyes peeled!
#4

[eluser]Derek Allard[/eluser]
Hey e-man. Welcome to CI, the dark-underbelly of EllisLab Wink

You could enable PHP in a template and then explicitly include the helper file you want. I know you were looking for something a bit more automagic, but as of right now, that's how it'd need to be done.
#5

[eluser]e-man[/eluser]
That completely slipped my mind...
so a simple
Code:
include '/path/to/helpername.php';
would suffice then?
#6

[eluser]Tom Glover[/eluser]
Yes the call the function by name with out $this-> or $this->helper->...
#7

[eluser]Derek Allard[/eluser]
Well, you don't use $this->helper with helpers anyhow, but you're right wackywebs if we were trying to use libraries it would take a little more playing.

The only thing I can think of offhand is that each helper has
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

at the top, which will prevent the file from loading. This is easily worked around by just defining that constant. Here's an example

Enable php in a template (on output). Put the "helpers" library into your root directory.

Code:
<?php
define('BASEPATH', 'workaround');
include "helpers/string_helper.php";

echo repeater("ice ", 2) . "baby!";
?>
#8

[eluser]e-man[/eluser]
Can't believe you snuck in a reference to Eminem's granddad in there Derek, truly evil Smile
Jest aside, thanks for the info, I'll have a play with it...
#9

[eluser]Derek Allard[/eluser]
[quote author="e-man" date="1213415123"]Can't believe you snuck in a refefrence to Eminem's granddad in there Derek, truly evil Smile
[/quote]

Dude, that's nothing. I've been much, much, much worse in the past Wink




Theme © iAndrew 2016 - Forum software by © MyBB