related() problem v latte : Call to a member function related() on a non-object

- blueticket
 - Člen | 41
 
Dobry den,
snazim se udelat sablonu s komentama pro timeline. Timeline row zobrazuji a vse funguje naderne. Jenomze kdyz se pokusim zobrazit komentare ke kazdemu eventu pres related() dostanu chybu:
Call to a member function related() on a non-object
takhle vypada sablona (zjednodusene):
{foreach $timeline_rows as $row}
            {snippet areaComments}
                {snippet comment-$row->id}
                    {foreach $row->related("tbl_comments.timeline_id") as $row_comments}
                        <div class="col-lg-12 col-md-12 col-xs-12" style="padding:5px 0px 5px 0px;border-top:#EDEBE4 1px solid;">
                            <img class="user-block-thumb" src="img/dog1.jpg"/>
                            <span class="notification-item-header text-uppercase"><a n:href="" style="color:#a5987f;">Viktorij Dogshow</a></span>
                            <span class="notification-item-event-time">{$row_comments->comment_date_time|date:'%d.%m.%Y'}</span>
                            <span class="notification-item-event" style="color:black">{$row_comments->comment}</span>
                        </div>
                    {/foreach}
                {/snippet}
            {/snippet}
{/foreach}
A takle plnim timeline_rows v presenteru:
// Data model
    function getTimeline($id = 0) {
        $rows = NULL;
        if ($id == 0)
            $rows = $this->database->query("SELECT tbl_timeline.*, (IF(tbl_timeline.profile_id>=300000000,(SELECT owner_profile_picture FROM tbl_userowner WHERE id=tbl_timeline.profile_id), (SELECT kennel_profile_picture FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_profile_image, (IF(tbl_timeline.profile_id>=300000000,(SELECT concat(tbl_user.name,' ',tbl_user.surname) as timeline_name FROM tbl_user WHERE tbl_user.id=(SELECT user_id FROM tbl_userowner WHERE id=tbl_timeline.profile_id)), (SELECT kennel_name FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_name FROM tbl_timeline order by `date` DESC");
        else
            $rows = $this->database->query("SELECT tbl_timeline.*, (IF(tbl_timeline.profile_id>=300000000,(SELECT owner_profile_picture FROM tbl_userowner WHERE id=tbl_timeline.profile_id), (SELECT kennel_profile_picture FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_profile_image, (IF(tbl_timeline.profile_id>=300000000,(SELECT concat(tbl_user.name,' ',tbl_user.surname) as timeline_name FROM tbl_user WHERE tbl_user.id=(SELECT user_id FROM tbl_userowner WHERE id=tbl_timeline.profile_id)), (SELECT kennel_name FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_name FROM tbl_timeline where profile_id = ? order by `date` DESC", $id);
        return $rows;
    }
// Presenter:
        $this->template->timeline_rows = $this->data_model->getTimeline($id);
Muzete mi prosim poradit, co zas delam blbe?
Dik moc

- David Matějka
 - Moderator | 6445
 
Ajo uz to vidim.. jelikoz pouzivas normalni sql a nevyuzivas NDBT
($database->table()), tak related nebude fungovat.

- blueticket
 - Člen | 41
 
dokud vymyslim neco jineho, tak jsem predelal DataModel funkci, ktera vraci timeline rows, docasne tak, ze generuji temp tabulku, ale vysledek je porad stejny :( . Pro jistotu prikladam opet kody modelu controleru a template.
Fakt dekuju moc
Kod z DataModelu
    function getTimeline($id = 0) {
        $rows = NULL;
        $table = "tbl_" . rand(100000000, 999999999);
        if ($id == 0)
            $this->database->query("CREATE TABLE $table SELECT tbl_timeline.*, (IF(tbl_timeline.profile_id>=300000000,(SELECT owner_profile_picture FROM tbl_userowner WHERE id=tbl_timeline.profile_id), (SELECT kennel_profile_picture FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_profile_image, (IF(tbl_timeline.profile_id>=300000000,(SELECT concat(tbl_user.name,' ',tbl_user.surname) as timeline_name FROM tbl_user WHERE tbl_user.id=(SELECT user_id FROM tbl_userowner WHERE id=tbl_timeline.profile_id)), (SELECT kennel_name FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_name FROM tbl_timeline order by `date` DESC");
        else
            $this->database->query("CREATE TABLE $table SELECT tbl_timeline.*, (IF(tbl_timeline.profile_id>=300000000,(SELECT owner_profile_picture FROM tbl_userowner WHERE id=tbl_timeline.profile_id), (SELECT kennel_profile_picture FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_profile_image, (IF(tbl_timeline.profile_id>=300000000,(SELECT concat(tbl_user.name,' ',tbl_user.surname) as timeline_name FROM tbl_user WHERE tbl_user.id=(SELECT user_id FROM tbl_userowner WHERE id=tbl_timeline.profile_id)), (SELECT kennel_name FROM tbl_userkennel WHERE tbl_userkennel.id=tbl_timeline.profile_id))) as timeline_name FROM tbl_timeline where profile_id = ? order by `date` DESC", $id);
        $this->database->query("ALTER TABLE $table ADD PRIMARY KEY (`id`)");
        $rows = $this->database->table($table);
        //$this->database->query("DROP TABLE IF EXISTS $table");
        return $rows;
    }
Kod v presenteru :
        $this->template->timeline_rows = $this->data_model->getTimeline($id);
Kod sablony
{foreach $timeline_rows as $row}
            {snippet areaComments}
                {foreach $row->related("tbl_comments.timeline_id") as $row_comments}
                    {snippet comment-$row->id}
                        <div class="col-lg-12 col-md-12 col-xs-12" style="padding:5px 0px 5px 0px;border-top:#EDEBE4 1px solid;">
                            <img class="user-block-thumb" src="img/dog1.jpg"/>
                            <span class="notification-item-header text-uppercase"><a n:href="" style="color:#a5987f;">Viktorij Dogshow</a></span>
                            <span class="notification-item-event-time">{$row_comments->comment_date_time|date:'%d.%m.%Y'}</span>
                            <span class="notification-item-event" style="color:black">{$row_comments->comment}</span>
                        </div>
                    {/snippet}
                {/foreach}
            {/snippet}
{/foreach}
Nemuze byt problem v tom prenaseni $rows DataModel ⇒ Presenter ⇒ View?

- blueticket
 - Člen | 41
 
takze funguje to, jen ten foreach nemuze byt soucasti zadneho snippetu.
Editoval blueticket (11. 8. 2015 14:53)