我试过这个:
$items = ($report->http_response_body->items );
$this->view->assign('items', $items);
$this->view->assign('page', $report->http_response_body->paging);
{item.timestamp} <f:format.date format="d.m.Y - H:i:s">@{item.timestamp}</f:format.date>
但它会像这样渲染不同的 tiamstamps(要么完全失败,要么渲染不正确):
1435146156.574 "@1435146156.574" could not be parsed by DateTime constructor.
1435146154.602 "@1435146154.602" could not be parsed by DateTime constructor.
1435141273.1495 24.06.1540 - 05:21:13
这些项目来自 mailgun 响应 https://documentation.mailgun.com/api-events.html#examples
这也是后端模块,那么我将如何处理分页? 到目前为止我已经有了这个
<f:link.action class="button show" action="list" arguments="{page : page.first}">First</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.previous}">Previous</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.next}">Next</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.last}">Last</f:link.action>
但是当您单击链接时,会出现错误:
Oops, an error occured! The endpoint you've tried to access does not exist. Check your URL.
谢谢(抱歉,我是个新手,但我以前从未写过后端模块) PS 为了达到这一点,我必须将后端模板复制到一个文件夹中才能找到,所以现在我的后端模块使用在 Resources/Private/Templates 下找到的默认模板,而不是在 Resources/Backend/Private/Templates 下找到,这里是我的列表模板:
<f:layout name="Default" />
This Template is responsible for creating a table of domain objects.
If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
Resources:
Private:
Templates:
List.html: keep
Otherwise your changes will be overwritten the next time you save the extension in the extension builder
<f:section name="content">
<h1>Listing for MailgunLog</h1>
<f:flashMessages />
<table class="tx_mailgunlog" >
<tr>
<th> Date</th>
<th> Summary</th>
</tr>
<f:for each="{items}" as="item">
<tr>
<td>{item.timestamp} <f:format.date format="d.m.Y - H:i:s">@{item.timestamp}</f:format.date> </td>
<td> {item.event} {item.recipient} {item.message.headers.subject} </td>
</tr>
</f:for>
</table>
<f:link.action class="button show" action="list" arguments="{page : page.first}">First</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.previous}">Previous</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.next}">Next</f:link.action>
<f:link.action class="button show" action="list" arguments="{page : page.last}">Last</f:link.action>
</f:section>
谢谢!
PS:感谢 mtness,我将此代码添加到控制器中以修复日期问题:
foreach($report->http_response_body->items as $item){
if(strpos($item->timestamp, ".")!==FALSE){
$item->timestamp = strstr($item->timestamp, '.', TRUE);
}
}
现在要解决链接问题。
由于操作全部在 listAction 中,我想我应该发布函数 sig:
/**
* action list
* @param string emailaddress to search for
* @param string PAGE IF THERE IS PAGING TO BE DONE
* @return void
*/
public function listAction($email ='', $page='') {
现在我必须像这样添加一个快速破解:
$getvars = t3lib_div::_GET();
$email = mysql_real_escape_string($getvars["email"]);
$page = mysql_real_escape_string($getvars["page"]);
$report = $this->report($email, $page);
然后将分页网址附加到链接中,如下所示:
<f:if condition="{page.first}">
<a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.first}">First</a>
</f:if>
<f:if condition="{page.previous}">
<a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.previous}">Previous</a>
</f:if>
<f:if condition="{page.next}">
<a href="mod.php?M=web_MailgunlogMailgunlog&page={page.next}">Next</a>
</f:if>
<f:if condition="{page.last}">
<a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.last}">Last</a>
</f:if>
通过电子邮件搜索如下所示:
<form action="http://www.ontariotaxsales.ca/typo3/mod.php?" method="GET">
<input type="hidden" name="M" value="web_MailgunlogMailgunlog"/>
Email Search <input name="email" type="email" />
</form>
/**
* Report
* show outbound log from mailgun
* @param string email
* @param string page the paging url
* @return void
*/
public function report( $email='', $page='' ) {
$APIKey = 'key-...';
$MailgunDomain = 'https://api.mailgun.net/v3/outbound.....ca/events';
$mgClient = new Mailgun($APIKey);
# Issue the call to the client.
$queryString = array(
'pretty' => 'no'
);
if($page !=''){
$MailgunDomain = $page;
}
if ($email != '') {
$queryString['recipient']=$email;
}
# Make the call to the client.
$result = $mgClient->get("$MailgunDomain", $queryString );
return $result ;
}
这是一个丑陋无耻的黑客行为,但我需要尽快完成它。