2014-05-14 4 views
0

저는 Modx가 새롭고이 테이블의 데이터를 표시하는 간단한 스 니펫 (snippet)을 만드는 방법을 생각할 수 없습니다.Modx Revolution 2.2.8-pl 간단한 데이터베이스 테이블 쿼리

<?php 
$output = ''; 
$result = $modx->query("SELECT item_title,item_username,item_date,item_image FROM modx_wayfinder"); 

    foreach ($result as $row){ 

    $properties['item_title'] = $row['item_title']; 
    $properties['item_username'] = $row['item_username']; 
    $properties['item_date'] = $row['item_date']; 
    $properties['fav_image'] = $row['item_img']; 

    $output = $modx->getChunk('src-res-item.searchbox.main_page',$properties); 

    }; 
    return $output; 

?> 

내가 데이터를 출력하기 위해 노력하고있어이를 통해 템플릿 :

<div class="cs-item"> 
    <a href="#" class="cs-attachment only-lrg"> 
    <img src="[[+fav_image]]" alt="main attachment"> 
    </a> 
    <ul class="cs-head"> 
    <li class="cs-title"> 
     <h4><a href="#">[[+item_title]]</a></h4> 
    </li> 
    </ul> 
    <div class="cs-body"> 
    <div class="cs-item-details"> 
     <p>Posted by <a href="#" class="user-name" data-ajax="false">[[+item_username]]</a> on <a href="#" class="post-date" data-ajax="false">[[+item_date]]</a></p> 
     <p>Located in <a href="#" class="item-location" data-ajax="false">[[+item_loc_country]], [[+item_loc_city]]</a></p> 
     <p>The item has been viewed <span class="item-views">[[+views]]</span> times</p> 
    </div> 
    </div> 
    <div class="cs-footer only-sml"> 
    <a href="[[~10]]" class="btn" data-ajax="false">View item</a> 
    <a href="[[~11]]" class="btn btn-alt" data-ajax="false">Contact user</a> 
    </div> 
</div> 

내가 찾던를

<?xml version="1.0" encoding="UTF-8"?> 
<model package="wayfinder" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1"> 

    <object class="wayfindertable" table="wayfinder" extends="xPDOSimpleObject"> 

    <fields ..... /> 

</object> 
</model> 

내 조각은 다음과 같이 보입니다 지난 몇 시간 동안 대답을 찾지 못했고 내가 찾고있는 것과 비슷한 간단한 쿼리를 설명하는 간단한 문서를 찾을 수 없습니다.

도움을 주시면 감사하겠습니다.

아, 그리고 현재지고있어 오류는 다음과 같습니다

Warning: Invalid argument supplied for foreach() in .../core/cache/includes/elements/modsnippet/82.include.cache.php on line 12 

종류의 안부

알렉스

LATER 편집 할 수 있습니다.

션 킴볼 덕분에 나는 테이블을 하나의 요소를 인쇄하는 데 매우 효과적이었습니다.

<?php 
$output = ''; 
$results = $modx->query('SELECT * FROM `modx_wayfinder` ORDER BY ID'); 

while ($row = $results->fetch(PDO::FETCH_ASSOC)) { 
     $properties['item']['title'] = $row['item_title']; 
     $properties['item']['author'] = $row['item_author']; 
     $properties['item']['country'] = $row['item_loc_country']; 
     $properties['item']['city'] = $row['item_loc_city']; 
     $properties['item']['date'] = $row['item_date']; 
     $properties['fav']['image'] = $row['item_img']; 
     $output = $modx->getChunk('src-res-item.searchbox.main_page',$properties); 
     return $output; 
     exit; 
} 

답변

0

당신은 뭔가를 시도 할 수 있습니다 : 그것은 아주 잘 여기 문서화

$results = $modx->query("SELECT * FROM some_table"); 
while ($r = $results->fetch(PDO::FETCH_ASSOC)) { 
     print_r($r); exit; 
} 

: 넣은는 Wayfinder 모델을 흔들어 경우 http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.query

또한, 모든없이 할 수 있어야 여분의 SQL, getObject, getCollection : http://rtfm.modx.com/xpdo/2.x/getting-started/using-your-xpdo-model/retrieving-objects

+0

예, 작동했으나 하나의 항목 만 표시합니다. – user2708284

+0

"Wayfinder"라는 이름은이 경우 이름의 우연 일뿐입니다 :) – user2708284

+0

'exit; 루프가 한 번만 실행되도록 허용하고 있습니다 ... 충돌 가능성을 피하기 위해 여분의 이름을 바꿀 수도 있습니다. runSnippet 호출에서이 코드를 사용해야한다면 modx가 대신 WayFinder 스 니펫을 실행하려고 시도합니다. 그냥 제안. –