在cakephp中调用函数

时间:2013-03-27 09:21:59

标签: php function cakephp

public function data()
{ 
if($old != $status || $prev_lat != $lat || $prev_long != $long)
            {
                if($status == 'Village' || 'Unknown')
                {
                    exec_query();
                }
                else if($status == 'Town' || 'City')
                {
                    exec_query();
                }   
            }
}


public function exec_query()
{
    //Some data;
}

但每当我调用此函数时,我会收到如下错误: -

Call to undefined function exec_query() 

任何人都可以告诉我如何在cakephp中调用函数

1 个答案:

答案 0 :(得分:11)

在函数名称之前添加$this->,如下所示:

public function data()
{ 
if($old != $status || $prev_lat != $lat || $prev_long != $long)
            {
                if($status == 'Village' || 'Unknown')
                {
                    $this->exec_query();
                }
                else if($status == 'Town' || 'City')
                {
                    $this->exec_query();
                }   
            }
}


public function exec_query()
{
    //Some data;
}