[eluser]tinawina[/eluser]
This has to be easy! But new to CI and OOP and I'm just not able to get this simple thing to work.
As a first step, I just want to display a page that gets a variable from the data array from a homemade function that I have placed in a homemade helper file. I understand from the User Guide that I can create my own helper files and either place them in the system "helpers" folder or place them in a folder that I create and label "helpers" in my "application" folder. CI will look in the applications/helpers folder first, and if not found there, it will check the system/helpers folder. All of the functions contained in the file can be used throughout my application -- global scope. As long as I label my files so that they end with "_helper.php" I should be good to go.
Ok. I've created a "helpers" folder in my application folder, and I made a helper file called "my_helper.php". Here's the contents of that file:
application/helpers/my_helper.php
Code:
function hello() {
$data['message'] = 'Hi there!';
}
Here's my controller file:
application/controllers/test.php
Code:
class Test extends Controller {
function Test()
{
parent::Controller();
$this->load->helper('my'); // according to the User Guide, I don't have to tell CI where to find this file, or show the "_helper.php" part.
}
function index()
{
$data['testing'] = "Testing this out.";
hello();
$this->load->view('test', $data);
}
}
And here's my view file:
application/views/test.php
Code:
<html>
<head>
<title>test</title>
</head>
<body>
<p><?php echo $testing; ?></p>
<p><?php echo $message; ?></p>
</body>
</html>
When I peek at this in my browser, I see:
Testing this out.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: message
Filename: views/test.php
Line Number: 10
So it's showing me $data['testing'] but not $data['message'] which is tucked away in the my_helper.php file but should be available to the entire application. I think.
Really feeling like a neeeewbiiiiiie.... Appreciate any help offered!