2013-07-23 35 views
0

我試圖使我的枝條頁面上的數組,但我總是碰到下面的錯誤代碼:的Symfony2 /嫩枝 - 錯誤信息:注意:試圖讓非對象的財產

異常被在ProfileBundle中渲染模板(「注意:嘗試獲取C:\ xampp \ htdocs \ JPP \ app \ cache \ dev \ classes.php行10098中的非對象屬性」):Profile:profile.html在線路228

.twig當我看着profile.html.twig我看到下面的for循環:

    `{% for Educations in Education|sortByDate %} 
        <div id="education{{loop.index0}}">        
          <tr> 
           <td class="border">{{ Educations.fromDate|date('d-m-Y') }}</td> 
           <td>&nbsp;</td> 
           <td class="border">{{ Educations.toDate|date('d-m-Y') }}</td> 
           <td>&nbsp;</td>          
           <td class="border">{{ Educations.company }}</td> 
           <td>&nbsp;</td> 
           <td class="border" id="jobsChar{{loop.index0}}">{{ Educations.jobs }}</td> 
           <td>&nbsp;</td> 
           <td class="border"><input type="button" title="Show Details" class="showDetails" id="details_show{{loop.index0}}"/><input type="button" title="Edit" class="editJob" id="education_edit{{loop.index0}}" /><form style="display:inline" action="../deleteJob" id="deleteJob"><input type="button" title="Delete Job" class="deleteJob" id="job_delete{{loop.index0}}" /></form></td> 
          </tr></div>{% endfor %}` 

在下面你可以看到應該由TWIG的for循環處理的數組,但是沒有成功...

array(5){[0] => array(9){[「id」 ] => int(80)[「userId」] => int(3)[「company」] => string(24)「SolothurnerSpitälerAG」[「jobArea」] => int(0)[「subJobsArea」] => int(2)[「jobLabel」] => string(8)「Förster」[「fromDate」] => object(DateTime)#437(3){[日期「] =>字符串(19)」2010-01-01 00:00:00「[」timezone_type「] => int(3)[」timezone「] => string(13)」Europe/Berlin「} [ 「toDate」] => object(DateTime)#436(3){[「date」] => string(19)「2011-02-09 00:00:00」[「timezone_type」] => int(3) [「timezone」] => string(13)「Europe/Berlin」}} [1] => array(9){[「id」] => int(87)[「userId」] => int(3) [「company」] => string(6)「TOP IT」[「jobArea」] => int(0)[「subJobsArea」] => int(0)[「jobs」] => int(3)[「 jobLabel「] => string(20)」Dipl。 Pflegefachfrau「[」fromDate「] => object(DateTime)#433(3){[」date「] => string(19)」2008-05-01 00:00:00「[」timezone_type「] => int (3)[「timezone」] => string(13)「Europe/Berlin」} [「toDate」] => object(DateTime)#432(3){[「date」] => string(19) (3)[「timezone」] => string 「id」] => int(103)[「userId」] => int(3)[「company」] => string(10)「Helsana AG」[「jobArea」] => int(0)[「subJobsArea 「] => int(0)[」jobs「] => int(1)[」jobLabel「] => string(11)」Holffäller「[」fromDate「] => object(DateTime)#430(3){ 「」date「] => string(19)」2012-10-01 00:00:00「[」timezone_type「] => int(3)[」timezone「] => string(13)」Europe/Berlin「 } [「toDate」] => object(DateTime)#429(3){[「date」] => string(19)「2013-05-01 00:00:00」[「timezone_type」] => int( 3)[「timezone」] => string(13)「Europe/Berlin」}} [3] => array(9){[「id」] => int(104)[「userId」] => int( 3)[「company」] => string(8)「ALPIQ AG」[「jobArea」] => int(0)[「subJobsArea」] => int(0)[「jobs」] => int(2) [「工作(「Date」)=> string(8)「Förster」[「fromDate」] => object 00「[」timezone_type「] => int(3)[」timezone「] => string(13)」Europe/Berlin「} [」toDate「] => object(DateTime)#426(3){[ 「] => string(19)」2013-05-09 00:00:00「[」timezone_type「] => int(3)[」timezone「] => string(13)」Europe/Berlin「}} 4] => array(9){[「id」] => int(130)[「userId」] => int(3)[「company」] => string(8)「ALPIQ AG」[「jobArea」 ] => int(0)[「subJobsArea」] => int(0)[「jobs」] => int(2)[「jobLabel」] => string(8)「Förster」[「fromDate」] =>對象(DateTime)#424(3){[「date」] => string(19)「2013-05-01 00:00:00」[「timezone_type」] => int(3)[「timezone」] = > string(13)「Europe/Berlin」} [「toDate」] => object(DateTime)#439(3){[「date」] => string(19)「2013-05-09 00:00:00 「[」timezone_type「] => int(3)[」timezone「] => string(13)」Europe/Berlin「}}}

請幫助我嗎?非常感謝你。

Cheers Roger

+0

哪一行究竟是228?你在哪裏轉儲數組?在控制器或模板中? –

+0

錯誤可能在您的sortByDate過濾器中。你能發佈代碼嗎? – Webberig

+0

@Mohammad:{%for Education Education in | sortByDate%}是228行。對不起,我忘了提及行! – user2226918

回答

0

默認情況下,Twig將嘗試從過濾器中轉義返回的數據。 Twig可能不希望返回結果是一個數組並將其打破。定義Twig過濾器時,請嘗試將「is_safe」設置爲true。

如果這不起作用,我懷疑你可以使用這樣的過濾器。過濾器通常用於文本處理,而不是複雜的數據。你可以嘗試定義一個函數而不是過濾器,或者在最壞的情況下處理你的數據,你應該在哪裏=>控制器。

0

你的問題不是在樹枝上,在開頭{{ dump(Educations) }}添加一行,我相信它會返回null。 問題出在控制器上,你說你轉儲它,它的工作原理,但我假設你把它扔在控制器中,你可以添加行動代碼或最後幾行,看看你是如何通過該模板的變量。

0

你可以嘗試刪除 「| sortByDate」