开发者

creating functions in CodeIgniter controllers

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
    }
}
?>
开发者_StackOverflow社区

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?


This line is creating problem for you:

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

Replace with:

$outputdata['string'] = $this->_dprocess($data);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜