Adding singular example, adding charset setting to the main class.
This commit is contained in:
parent
21ae6ab5df
commit
0306241667
|
@ -113,6 +113,79 @@ Controller:
|
|||
|
||||
} // End Welcome
|
||||
|
||||
Grabbing a single model value
|
||||
-----
|
||||
|
||||
Model (This example uses [AutoModeler](http://github.com/zombor/Auto-Modeler)):
|
||||
|
||||
<?php
|
||||
|
||||
class Model_Test extends AutoModeler
|
||||
{
|
||||
protected $_table_name = 'tests';
|
||||
|
||||
protected $_data = array(
|
||||
'id' => '',
|
||||
'name' => '',
|
||||
'value' => '',
|
||||
);
|
||||
|
||||
protected $_rules = array(
|
||||
'name' => array('not_empty'),
|
||||
'value' => array('not_empty'),
|
||||
);
|
||||
}
|
||||
|
||||
View:
|
||||
|
||||
<?php
|
||||
|
||||
class View_Singular extends Kostache
|
||||
{
|
||||
protected $_pragmas = array(Kostache::PRAGMA_DOT_NOTATION => TRUE);
|
||||
|
||||
public $thing_id = NULL;
|
||||
public $title = 'Testing';
|
||||
|
||||
public function thing()
|
||||
{
|
||||
return new Model_Test($this->thing_id);
|
||||
}
|
||||
}
|
||||
|
||||
Template:
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>This is just one thing:</p>
|
||||
<h2>{{thing.id}}</h2>
|
||||
<ul>
|
||||
<li>Name: {{thing.name}}</li>
|
||||
<li>Value: {{thing.value}}</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Controller:
|
||||
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Welcome extends Controller {
|
||||
|
||||
public function action_singular($id)
|
||||
{
|
||||
$view = new View_Singular;
|
||||
$view->thing_id = $id;
|
||||
echo $view;
|
||||
}
|
||||
} // End Welcome
|
||||
|
||||
For specific usage and documentation, see:
|
||||
|
||||
[PHP Mustache](http://github.com/bobthecow/mustache.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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class View_Singular extends Kostache
|
||||
{
|
||||
protected $_pragmas = array(Kostache::PRAGMA_DOT_NOTATION => TRUE);
|
||||
|
||||
public $thing_id = NULL;
|
||||
public $title = 'Testing';
|
||||
|
||||
public function thing()
|
||||
{
|
||||
return new Model_Test($this->thing_id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>This is just one thing:</p>
|
||||
<h2>{{thing.id}}</h2>
|
||||
<ul>
|
||||
<li>Name: {{thing.name}}</li>
|
||||
<li>Value: {{thing.value}}</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue