Permalink
Browse files

Merged @JoeChilds changes, updated interfaces and README

  • Loading branch information...
root
root committed Jun 17, 2013
1 parent aeac8d4 commit b4b8ddb03091d73347490e151d3a0f09a75ebe12
View
@@ -55,7 +55,7 @@ class Foo extends \Swiftlet\Controller
public function index()
{
// Pass a variable to the view
$this->view->set('helloWorld', 'Hello world!');
$this->view->helloWorld = 'Hello world!';
}
}
```
@@ -64,13 +64,13 @@ Important: class names are written in
[CamelCase](http://en.wikipedia.org/wiki/CamelCase) and match their filename.
**View `views/foo.html.php`**
**View `views/foo.php`**
```php
<h1><?php echo $this->get('pageTitle') ?></h1>
<h1><?php echo $this->pageTitle ?></h1>
<p>
<?php echo $this->get('helloWorld') ?>
<?php echo $this->helloWorld ?>
</p>
```
@@ -125,7 +125,7 @@ The action name and arguments can be accessed through
Note: to use a different view for each action you may change the value of
`$this->view->name`. The view name is a filename relative to the `view`
directory, without the `.html.php` suffix.
directory, without the `.php` suffix.
Models
@@ -165,7 +165,7 @@ class Foo extends \Swiftlet\Controller
$helloWorld = $exampleModel->getHelloWorld();
$this->view->set('helloWorld', $helloWorld);
$this->view->helloWorld = $helloWorld;
}
}
```
@@ -200,7 +200,7 @@ class Foo extends \Swiftlet\Plugin
{
// Overwrite our previously set "helloWorld" variable
if ( get_class($this->controller) === 'Swiftlet\Controllers\Foo' ) {
$this->view->set('helloWorld', 'Hi world!');
$this->view->helloWorld = 'Hi world!';
}
}
}
@@ -236,7 +236,7 @@ $this->app->setConfig('variable', 'value');
$value = $this->app->getConfig('variable');
```
Values can be set in `config.php` or a custom file.
Values can be set in `config/main.php` or a custom file.
--------------------------------------------------------------------------------
@@ -268,6 +268,9 @@ Create a new model instance
* `object getSingleton(string $modelName)`
Create or return an existing model instance
* `string getControllerName()`
Name of the controller
* `string getRootPath()`
Absolute client-side path to the website root
@@ -18,10 +18,7 @@ public function index()
// Create a model instance, see /Swiftlet/Models/Example.php
$exampleModel = $this->app->getModel('example');
// Get some data from the model
$helloWorld = $exampleModel->getHelloWorld();
// Pass the data to the view to display it
$this->view->set('helloWorld', $helloWorld);
// Get some data from the model and pass it to the view to display it
$this->view->helloWorld = $exampleModel->getHelloWorld();
}
}
@@ -14,6 +14,8 @@ public function setConfig($variable, $value);
public function getRootPath();
public function getControllerName();
public function getAction();
public function getArgs();
@@ -8,8 +8,12 @@ public function __construct(App $app, $name);
public function get($variable, $htmlEncode = true);
public function __get($variable);
public function set($variable, $value = null);
public function __set($variable, $value = null);
public function htmlEncode($value);
public function htmlDecode($value);
@@ -10,9 +10,7 @@ class Example extends \Swiftlet\Plugin
public function actionAfter()
{
if ( get_class($this->controller) === 'Swiftlet\Controllers\Index' ) {
$helloWorld = $this->view->get('helloWorld');
$this->view->set('helloWorld', $helloWorld . ' This string was altered by ' . __CLASS__ . '.');
$this->view->helloWorld .= ' This string was altered by ' . __CLASS__ . '.';
}
}
}
View
@@ -39,6 +39,18 @@ public function get($variable, $htmlEncode = true)
return $this->variables[$variable];
}
}
return null;
}
/**
* Magic method to get a view variable, forwards to $this->get()
* @param string $variable
* @return mixed
*/
public function __get($variable)
{
return $this->get($variable);
}
/**
@@ -51,6 +63,16 @@ public function set($variable, $value = null)
$this->variables[$variable] = $value;
}
/**
* Magic method to set a view variable, forwards to $this->set()
* @param string $variable
* @param mixed $value
*/
public function __set($variable, $value = null)
{
$this->set($variable, $value);
}
/**
* Recursively make a value safe for HTML
* @param mixed $value
File renamed without changes.
View
@@ -1,6 +1,6 @@
<?php require('header.php') ?>
<h1><?php echo $this->get('pageTitle') ?></h1>
<h1><?php echo $this->pageTitle ?></h1>
<p>
Page not found.
View
@@ -2,7 +2,7 @@
<html>
<head>
<title><?php echo $this->htmlEncode($this->app->getConfig('siteName')) . ' - ' . $this->get('pageTitle') ?></title>
<title><?php echo $this->htmlEncode($this->app->getConfig('siteName')) . ' - ' . $this->pageTitle ?></title>
<link type="text/css" rel="stylesheet" href="<?php echo $this->app->getRootPath() ?>views/css/layout.css">
</head>
View
@@ -1,9 +1,9 @@
<?php require 'header.php' ?>
<h1><?php echo $this->get('pageTitle') ?></h1>
<h1><?php echo $this->pageTitle ?></h1>
<p>
<?php echo $this->get('helloWorld') ?>
<?php echo $this->helloWorld ?>
</p>
<?php require 'footer.php' ?>
View
@@ -1,10 +0,0 @@
User-agent: *
Disallow: /Swiftlet/
Disallow: /tests/
Disallow: /views/
Disallow: /config.php
Disallow: /COPYING
Disallow: /README
User-Agent: T-800
Disallow: /john/connor
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -15,7 +15,7 @@
spl_autoload_register(array($app, 'autoload'));
require 'config/config.php';
require 'config/main.php';
$app->run();
$app->serve();
File renamed without changes.
View
@@ -0,0 +1,4 @@
User-agent: *
User-Agent: T-800
Disallow: /john/connor

0 comments on commit b4b8ddb

Please sign in to comment.