4

I have a CodeIgniter application, but one of my controllers must call a data processing function that I have also written myself. The only problem is I can't seem to figure out how to do this. Looking through the user guide it seems that I should put my function inside the class declaration, and prefix it with an underscore (_) so that it cannot be called via the url. However, this is not working. Here's an example of what I mean:

<?php
class Listing extends Controller
{
    function index()
    {
        $data = "hello";
        $outputdata['string'] = _dprocess($data);
        $this->load->view('view',$outputdata);
    }
    function _dprocess($d)
    {
        $output = "prefix - ".$d." - suffix";
        return $output
    }
}
?>

The page keeps telling me I have a call to an undefined function _dprocess()

How do I call my own functions?

Thanks!
Mala

Edit:
I've gotten it to work by placing the function outside of the class declaration. Is this the correct way of doing it?

1
  • ideally, it should be inside the controller Commented Dec 12, 2009 at 10:56

1 Answer 1

7

This line is creating problem for you:

$outputdata['string'] = _dprocess($data);

Replace with:

$outputdata['string'] = $this->_dprocess($data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.