My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

Cobweb

Cobweb is a lightweight, extensible web framework for PHP, modeled after Django.

Batteries included.

Cobweb provides the C in Model-View-Controller and comes with batteries included: The Doctrine Object-Relational Mapper and Smarty templating engine makes Coweb a full-stack, fully-featured web framework.

Cobweb brings many of Django's core design ideas to PHP, such as:

  • pretty URLs with regular expression-based URL mappings
  • request-response cycle
  • the idea of projects and reusable applications
  • middleware
  • annotated actions
  • template loading

and more. Cobweb is currently in an early stage of development, but should be fully stable and usable in its current state. Read the tutorial to get started with your first Cobweb project!




High-level overview

1. Define a Doctrine model and build it

<?php // applications/wiki/models/wiki_page.model.php
class WikiPage extends Model {
  public function setTableDefinition() {
    $this->hasColumn('title', 'string', NULL, array('notnull' => true));
    $this->hasColumn('wikiword', 'string', NULL, array('unique' => true, 'notnull' => true));
    $this->hasColumn('created', 'timestamp', array('notnull' => true));
    $this->hasColumn('body', 'string');
  }
}
> cobweb doctrine-build
cobweb: Built 1 model(s) sucessfully

2. Define a URL structure

<?php // settings/urls.conf.php
return array(
  '^$' => 'wiki.wiki.index',
  '^page/(?P<wiki_word>\w+)$' => 'wiki.wiki.page',
); 

3. Implement a controller action (may be any PHP callable)

<?php // applications/wiki/wiki.controller.php
class WikiController extends Controller {
  public function page($wiki_word) {
    $wiki_page = Model::table('WikiPage')->findOneByWikiword($wiki_word);
    if (!$wiki_page)
      throw new HTTP404();
    return $this->render('wiki_page.tpl', array('wiki_page' => $wiki_page));
  }
}

4. Write a template

<!-- templates/wiki_page.tpl -->	
<!DOCTYPE html>
<head>
  <title>{$wiki_page->title}</title>
</head>
<body>
  <h1>{$wiki_page->title}</h1>
  {$wiki_page->body}
</body>
Powered by Google Project Hosting