Php Symfony中的getFirst不';我什么也不退

Php Symfony中的getFirst不';我什么也不退,php,symfony1,Php,Symfony1,我有一个关于symfony的问题。我在一个网站上工作,一切都进行得很顺利,突然,甚至没有碰一下,一切都停止了。我把它缩小到“getClient”函数中的一个问题。下面是代码:(如果有必要,我会使用doAuthPlugin) 在:app/client/lib/myUser.class.php中: public function getClient() { $uTemp = $this->getAccount()->getClients()->getFirst();

我有一个关于symfony的问题。我在一个网站上工作,一切都进行得很顺利,突然,甚至没有碰一下,一切都停止了。我把它缩小到“getClient”函数中的一个问题。下面是代码:(如果有必要,我会使用doAuthPlugin)

在:app/client/lib/myUser.class.php中:

public function getClient()
{

    $uTemp = $this->getAccount()->getClients()->getFirst();

    $userId = $uTemp['_data']['userid'];

    $q = Doctrine_Query::create()
        ->from('Client c')
        ->where('c.id  = ?', $userId);

    $result = $q->fetchArray();

    if(sizeof($result) > 0){

        return $this->getAccount()->getClients()->getFirst();
    }else{

        return false;
    }
}
public function getClientsAccount($id) 
    {        
        $q = $this->createQuery('u')
            ->where('u.client_id = ?', $id);

        return $q->execute();        
    } 
在第一行,$uTemp==false。虽然$this->getAccount()->getClients()中有一些内容

如果有人能解释一下,我真的很讨厌Symfonyp

谢谢

编辑:

下面是get帐户:

public function getAccount()
{
   if (!$this->user && $id = $this->getAttribute('user_id', null, 'doUser'))
   {
      $this->user = Doctrine::getTable('User')->find($id);

      if (!$this->user)
      {
        // the user does not exist anymore in the database
        $this->signOut();

        throw new sfException('The user does not exist anymore in the database.');
      }
    }

   return $this->user;
 }
我找不到GetClient,它是由symfony自动生成的(因为我对symfony不太了解…)

编辑2:

如果我在$this->getAccount->getClients()上执行var_转储,它将为空:

object(Client)#123 (18) {
  ["_node":protected]=>
  NULL
  ["_id":protected]=>
  array(0) {
  }
  ["_data":protected]=>
  array(14) {
    ["id"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["userid"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["name"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["firstname"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["phone"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["cellphone"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["postalcode"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["experience"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["connexe"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["formation"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["cv_file"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["is_active"]=>
    int(0)
    ["created_at"]=>
    object(Doctrine_Null)#12 (0) {
    }
    ["updated_at"]=>
    object(Doctrine_Null)#12 (0) {
    }
}
但是$this->getAccount确实返回了一些东西

可能getFirst()不适用于fetchArray()。 将此更改为:

$result = $q->execute();
可能这也适用于fetchArray():

对不起,我弄错了

如果使用$this->getAccount()->getClients(),那么是否也为NULL?也许$this->getAccount()->getClients()返回空值

更新:

$uTemp=$this->getAccountId();//(我不知道你的模式。yml)

在ClientsTable.class.php中:

public function getClient()
{

    $uTemp = $this->getAccount()->getClients()->getFirst();

    $userId = $uTemp['_data']['userid'];

    $q = Doctrine_Query::create()
        ->from('Client c')
        ->where('c.id  = ?', $userId);

    $result = $q->fetchArray();

    if(sizeof($result) > 0){

        return $this->getAccount()->getClients()->getFirst();
    }else{

        return false;
    }
}
public function getClientsAccount($id) 
    {        
        $q = $this->createQuery('u')
            ->where('u.client_id = ?', $id);

        return $q->execute();        
    } 
接下来在myUser.class.php中,您可以使用:

$clients = $this->getAccountId(); // (i dont know your schema.yml)

$uTemp = Doctrine_Core::getTable('Clients')->getClientsAccount($uTemp);
也许这也行得通:

$uTemp = Doctrine_Core::getTable('Clients')->getClientsAccount($uTemp)->getFirst();

祝你好运

OP没有在返回行中使用$result,因此fetchArray()对于快速回答来说并不重要(-1已删除):$this->getAccount()->getClients()不返回NULLtry parse this to array,并获取第一条记录我已经更新了getClients包含的部分内容。我无法解析数组的第一个元素,因为它是空的。首先获取帐户的id,然后在模型中编写自定义函数-获取帐户的客户端。您能否显示方法
getAccount()
getClients()