Skip to content

Instantly share code, notes, and snippets.

@rjd22
Created December 2, 2009 08:54
Show Gist options
  • Save rjd22/247059 to your computer and use it in GitHub Desktop.
Save rjd22/247059 to your computer and use it in GitHub Desktop.
// Controller
<?php defined('SYSPATH') or die('No direct script access.');
class Contact_Controller extends Website_Controller
{
public function index()
{
url::redirect();
}
public function view($contact_id)
{
$contact_model = new Contact_Model;
$contact = $contact_model->read_contact($contact_id)->current();
//we don't use this atm
//$contact_list = $contact_model->read_contact_list();
$this->template->content = new View('pages/contact');
$this->template->content->contact = $contact;
}
}
// Model
<?php defined('SYSPATH') or die('No direct script access.');
class Contact_Model extends Model
{
public function read_contact($contact_id)
{
$query = $db->query("
select
id,
firstname,
lastname
from
contacts
where
id = $contact_id
");
return $query;
}
public function read_contact_list()
{
$query = $db->query("
select
id,
firstname,
lastname,
phone,
email
from
contacts
");
return $query;
}
}
// View
<h3>View contact info for <?php echo $contact->firstname; ?></h3>
<table>
<tr>
<td><?php echo $contact->firstname; ?></td>
<td><?php echo $contact->lastname; ?></td>
<td><?php echo $contact->phone; ?></td>
<td><?php echo $contact->email; ?></td>
</tr>
</table>
//out put of view for the localhost/index.php/view/1 uri
View an individual Contact
Abe Lincolin 976-555-1212 honest@abe.com
// Error I get when I un comment the title line in the controller view()
An error was detected which prevented the loading of this page. If this problem persists, please contact the website administrator.
application/controllers/contact.php [17]:
Undefined property: Mysql_Result::$firstname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment