Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active December 16, 2015 12:59
Show Gist options
  • Save jamsesso/5438548 to your computer and use it in GitHub Desktop.
Save jamsesso/5438548 to your computer and use it in GitHub Desktop.
<?php
namespace Scarf\Views;
use Scarf\Models\Contacts;
use Scarf\Library\Layout\Templates;
/* Creates a URL at http://.../contacts */
class Contacts
{
/* The main page when /contacts is visited. */
public function main()
{
Templates::get("list_contacts", array(
"contacts" => Contacts::all()
));
}
/* Defines a page to add a contact: /contacts/add */
public function add()
{
Templates::get("add_contact");
}
/* Back end page to create a contact. Protected
functions are accessible during post requests. */
protected function create(Post $name, Post $phone)
{
Contacts::create([
"name" => $name,
"phone" => $phone
]);
redirect("Contacts");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment