Ben çok garip bir sorun ile mücadele ediyorum, ve bunu düzeltmek için görünmüyor olabilir.
Short version
When I execute a query from within a Doctrine_Record, it just doesn't seem to work when I try to get a related table. I get an Exception:
error: Uncaught PHP Error: Trying to get property of non-object in file D:/Tools/Development/xampp1.7/htdocs/x-interactive/xibits/application/views/issues/changeList.php on line 23
O satırda, ben mevcut tablonun alt tabloya almak için deneyin
Long version
Ben Kohana + Doctrine kullanıyorum. Ben gelen sonuçlar almak istiyorum üç tablo var.
Ben iki durumu vardır:
- Belirli bir tablonun tüm oğul göster
- Belirli bir tablonun bir oğul ABS
İlk durum için, bir (doktrin) sorgu yürütür ve sonucu döndürür bir modelde bir yöntem koyduk. Bu gayet güzel çalışıyor.
İkinci durum için, her şeyi almak için, ana doktrin kaydına bir yöntem eklemek için uygun görünüyordu, ama sonra süzülür. Ben bu sorguyu yürütmek Ama, ben ya da bilinmeyen bir sınıf istisna almak, ya da bir (Ben tam / getiri yürütmek ne bağlı olarak) bir nesne olmayan hata, bir başvuru almak için çalışıyorum. Sorunun kaynağına almaya çalışırken, ben bile sadece çalışması gereken ilk yöntemin sonucu dönmek, ama orada bile ben aynı hatayı alıyorum.
Bir Doctrine_Record içinde sorguyu yürütmek için bir sorun mu?
Doctrine_Record:
class Issue_History extends BaseIssue_History
{
public function getUserSafeItems()
{
$model = new Issue_History_Model();
return $model->fromIssueId(0);
}
}
Issue_History_Model:
public function fromIssueId($issue_id)
{
$q = Doctrine_Query::create()
->from("Issue_History IH, IH.Issue_History_Items IHI, IHI.Change_Types")
->where("IH.issue_id = ?", 3)
->orderBy("IH.date");
return $q->execute();
}
Bu kod kullanıldığında görünümü:
<?foreach($model->issue_history as $history): //$issue_history is the result of Issue_History_Model->fromIssueId($id)?>
<div class="changeItem">
<h4>Bijgewerkt door <?=$history->User->name?> <?=datehelper::getRelativeTime($history->date)?></h4>
<ul>
<?
if($model->showNonUserChanges || $history->hasUserSafeItems()): //In the case of the error, the first condition is false, but the last is true?>
$history_items = $model->showNonUserChanges ? $history->Issue_History_Items : $history->getUserSafeItems()->Issue_History_Items?>
<?foreach($history_items as $history_item):?>
<li><?=sprintf($history_item->Change_Types->text, $history_item->old_value, $history_item->new_value)//Exception happens here?></li>
<?endforeach?>
<?endif;?>
</ul>
</div>
<?endforeach;?>