2012-11-28 54 views
0

有人能看到为什么我的check_multi函数将返回 -不能模型内访问功能ZEND

Fatal error: Call to undefined function check_multi() in /var/www/vhosts/aero.onelinksoftware.com/application/models/Design.php on line 21

上述错误显示出来,我不知道我做错了。我尝试将我的功能设置为公共,私人,静态和其他组合,但不管我尝试什么;系统仍然出错。你不能在Zend中的Model中调用函数吗?我不明白为什么我不能使用我创建的函数,如果它在我创建的类中。

如果我在check_multi调用之前回声并死亡;我可以看到我的文字等。我还执行了语法的php测试,并且只要报告它就是有效的。

class Model_Design 
{ 
    /** 
    * Constructs our partials. 
    * 
    * @return void 
    */ 
    public function __construct($key) 
    { 
     // Get the DB Connection 
     $db = Zend_Registry::Get('db'); 
     // Setup the SQL Statement 
     $sql = $db->select()->from('design', array('id')); 
      // Get the Result 
      $result = $sql->query(); 
      // Get our Row 
      $row  = $result->fetchAll(); 

      if(check_multi($key, $row)) { 
       echo "omg"; die(); 
      } 

     // Make sure the id isn't empty 
     if (empty($key)) { 
      throw new Exception('You have a disturbing lack of variables.'); 
     } 

     // Store the id 
     $this->variables = $key; 


     // Construct our query 
     $sql = $db->select()->from('design')->where('`id` = ?', $key); 
      // Get the result 
      //$result = $sql->query(); 
      //$row = $result->fetch(); 
    } 

    private function check_multi($n, $arr) 
    { 
     foreach ($arr as $key => $val) { 
      if ($n===$key) { 
       return $key; 
      } 
     } 
     return false; 
    } 
} 

回答

1

尝试:

$this->check_multi($key, $row); 

从它的容器类的内部访问的变量或函数,你必须使用$此。 $这是该类的当前实例。

+0

这很好。谢谢!我正在拉我的头发。 – ILikeTurtles

1

如何调用该函数?使用$this->check_multi($n,$arr);或者您可以尝试function_exists()来检查功能是否真的存在

+0

这也是答案;因为它是正确的,但Iznogood首先回答。 – ILikeTurtles

+0

我是Stack overflow的新手。我在回答问题时正在输入答案 –

+0

@NavneetSingh是的,它经常是这样的。种族:)欢迎来到stackoverflow :) – Iznogood