Skip to content

Commit

Permalink
Merged @joechilds changes, updated interfaces and README
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 17, 2013
1 parent aeac8d4 commit b4b8ddb
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 31 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!';
}
}
```
Expand All @@ -64,13 +64,13 @@ Important: class names are written in
[CamelCase](http:https://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>
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,7 +165,7 @@ class Foo extends \Swiftlet\Controller

$helloWorld = $exampleModel->getHelloWorld();

$this->view->set('helloWorld', $helloWorld);
$this->view->helloWorld = $helloWorld;
}
}
```
Expand Down Expand Up @@ -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!';
}
}
}
Expand Down Expand Up @@ -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.


--------------------------------------------------------------------------------
Expand Down Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions Swiftlet/Controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions Swiftlet/Interfaces/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function setConfig($variable, $value);

public function getRootPath();

public function getControllerName();

public function getAction();

public function getArgs();
Expand Down
4 changes: 4 additions & 0 deletions Swiftlet/Interfaces/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions Swiftlet/Plugins/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__ . '.';
}
}
}
22 changes: 22 additions & 0 deletions Swiftlet/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion views/error404.php
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion views/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions views/index.php
Original file line number Diff line number Diff line change
@@ -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' ?>
10 changes: 0 additions & 10 deletions web/robots.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion web/index.php → www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

spl_autoload_register(array($app, 'autoload'));

require 'config/config.php';
require 'config/main.php';

$app->run();
$app->serve();
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions www/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *

User-Agent: T-800
Disallow: /john/connor

0 comments on commit b4b8ddb

Please sign in to comment.