我正在尝试为我的PHP脚本设置一个简单的MVC框架。 模特('会议'):
public function getConferenceLogs($pin){
$stmt_conferences = $this->db->prepare(
'SELECT
date_created,
timediff(date_completed, date_created) AS duration,
RecordURL,
conference_sid
FROM
conference
WHERE
pin=:pin');
$stmt_conferences->bindParam(':pin', $pin);
$stmt_conferences->execute();
$count = $stmt_conferences->rowCount();
if ($count !== 0) {
$row = $stmt_conferences->fetch();
return $row;
}
return false;
}
控制器:
function conference_history()
{
Auth::handleLogin();
$this->loadModel('conference');
$row = $this->model->getConferenceLogs(Session::get('user_pin'));
$this->view->row = $row;
$participant = $this->model->getParticipantLogs(Session::get('user_pin'));
$this->view->participant = $participant;
$this->view->render('account/conference_history');
}
查看:
<?php
var_dump($this->row);
?>
我知道模型中的这个查询应该返回至少7条记录,当在传统格式(https://stackoverflow.com/a/20275597/2429989) 的MVC框架外执行时p>
但是,var_dump($ this-&gt;行)会产生以下结果:
object(stdClass)[5]
public 'date_created' => string '2013-10-29 19:20:37' (length=19)
public 'duration' => string '00:03:42' (length=8)
public 'RecordURL' => string '' (length=0)
public 'conference_sid' => string '1c540158-40cf-11e3-b4cc-81e296145de2' (length=36)
我认为这意味着只有一条记录?我想显示所有7条记录;我设置了错误的查询还是我的echo语句?我想显示每个属性的所有7条记录(例如print $ this-&gt; row-&gt; date_created)。
答案 0 :(得分:2)
查看你的var_dump,$ this-&gt;行只是一个对象,它不能被转换为字符串。因此,您需要访问公共属性:
<?php
print $this->row->date_created;
...//repeat as needed
?>
或者,如果某种集合中有多个行对象
<?php
foreach($this->row_collection->row as $row){
print $row->date_created;
...//blah blah blah
}