Reputation: 8648
I am trying to set up a simple MVC framework for my PHP script. Model ('conference'):
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;
}
Controller:
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');
}
View:
<?php
var_dump($this->row);
?>
I know this query in the model should return at least 7 records, when executed outside an MVC framework in a conventional format (https://stackoverflow.com/a/20275597/2429989)
However, a var_dump($this->row) gives the following results:
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)
Which I assume means there is only one record? I want to display all 7 records; have I set up the query wrong or is it my echo statement? I want to display all 7 records for each property (e.g. print $this->row->date_created).
Upvotes: 0
Views: 74
Reputation: 3251
Looking at your var_dump, $this->row is just an object and it cannot be casted to a string. So, you'll want to access the public properties as such:
<?php
print $this->row->date_created;
...//repeat as needed
?>
Or if you have more than one row object in some sort of collection
<?php
foreach($this->row_collection->row as $row){
print $row->date_created;
...//blah blah blah
}
Upvotes: 2