From 03062416672b210141ddae32a9ff2c8c536f1a2a Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Mon, 17 May 2010 21:42:48 -0500 Subject: [PATCH] Adding singular example, adding charset setting to the main class. --- README.markdown | 73 +++++++++++++++++++++++++++++++++++++ classes/kostache.php | 2 + classes/view/example.php | 7 +--- classes/view/singular.php | 14 +++++++ templates/singular.mustache | 16 ++++++++ 5 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 classes/view/singular.php create mode 100644 templates/singular.mustache diff --git a/README.markdown b/README.markdown index 3efc801..985b401 100644 --- a/README.markdown +++ b/README.markdown @@ -113,6 +113,79 @@ Controller: } // End Welcome +Grabbing a single model value +----- + +Model (This example uses [AutoModeler](http://github.com/zombor/Auto-Modeler)): + + '', + 'name' => '', + 'value' => '', + ); + + protected $_rules = array( + 'name' => array('not_empty'), + 'value' => array('not_empty'), + ); + } + +View: + + TRUE); + + public $thing_id = NULL; + public $title = 'Testing'; + + public function thing() + { + return new Model_Test($this->thing_id); + } + } + +Template: + + + + + + {{title}} + + +

{{title}}

+

This is just one thing:

+

{{thing.id}}

+ + + + +Controller: + + thing_id = $id; + echo $view; + } + } // End Welcome + For specific usage and documentation, see: [PHP Mustache](http://github.com/bobthecow/mustache.php) diff --git a/classes/kostache.php b/classes/kostache.php index 61c5bae..c9254dc 100644 --- a/classes/kostache.php +++ b/classes/kostache.php @@ -6,6 +6,8 @@ class Kostache extends Mustache { parent::__construct($template, $view, $partials); + $this->_charset = Kohana::$charset; + // Override the template location to match kohana's conventions if ( ! $this->_template) { diff --git a/classes/view/example.php b/classes/view/example.php index b1a1661..42941c4 100644 --- a/classes/view/example.php +++ b/classes/view/example.php @@ -11,11 +11,6 @@ class View_Example extends Kostache public function tests() { - $tests = array(); - foreach (AutoModeler::factory('test')->fetch_all() as $test) - { - $tests[] = $test->as_array(); - } - return $tests; + return AutoModeler::factory('test')->fetch_all(); } } \ No newline at end of file diff --git a/classes/view/singular.php b/classes/view/singular.php new file mode 100644 index 0000000..0b33908 --- /dev/null +++ b/classes/view/singular.php @@ -0,0 +1,14 @@ + TRUE); + + public $thing_id = NULL; + public $title = 'Testing'; + + public function thing() + { + return new Model_Test($this->thing_id); + } +} \ No newline at end of file diff --git a/templates/singular.mustache b/templates/singular.mustache new file mode 100644 index 0000000..b47a37f --- /dev/null +++ b/templates/singular.mustache @@ -0,0 +1,16 @@ + + + + + {{title}} + + +

{{title}}

+

This is just one thing:

+

{{thing.id}}

+ + + \ No newline at end of file