Skip to content

Commit

Permalink
deprecated Viewmodel; introduced Presenter; documented Namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed May 17, 2014
1 parent 779ca3f commit 6c3b4a0
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 192 deletions.
4 changes: 3 additions & 1 deletion assets/js/combined.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions classes/security.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h3 id="configuration">Configuration</h3>
<td>array</td>
<td><pre class="php"><code>array('Security::htmlentities')</code></pre></td>
<td>
Array of callable items (PHP functions, object methods, static class methods) used to filter variables send to a View or Viewmodel.
Array of callable items (PHP functions, object methods, static class methods) used to filter variables send to a View or Presenter.
For security reasons, you are <strong>required</strong> to define an output filter.
</td>
</tr>
Expand Down Expand Up @@ -140,7 +140,7 @@ <h3 id="configuration">Configuration</h3>
<tr>
<th>whitelisted_classes</th>
<td>array</td>
<td><pre class="php"><code>array('stdClass', 'Fuel\\Core\\View',<br /> 'Fuel\\Core\\ViewModel', 'Closure')</code></pre></td>
<td><pre class="php"><code>array('stdClass', 'Fuel\\Core\\View',<br /> 'Fuel\\Core\\Presenter', 'Closure')</code></pre></td>
<td>
When auto encoding of view variables is enabled, you can run into issues when passing objects to the view. Classes defined in this
array will be exempt from auto encoding.
Expand Down
16 changes: 8 additions & 8 deletions classes/theme/methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ <h4 class="method" id="method_view">view($view, $data = array(), $auto_filter =
</article>

<article>
<h4 class="method" id="method_viewmodel">viewmodel($view, $method = 'view', $auto_filter = null)</h4>
<h4 class="method" id="method_presenter">presenter($view, $method = 'view', $auto_filter = null)</h4>
<p>
The <strong>viewmodel</strong> method loads and return a Viewmodel object based on the $view string passed. It
will use the <strong>view</strong> method documented above to pass the theme view to the Viewmodel.
The <strong>presenter</strong> method loads and return a Presenter object based on the $view string passed. It
will use the <strong>view</strong> method documented above to pass the theme view to the Presenter.
</p>

<table class="method">
Expand All @@ -272,13 +272,13 @@ <h4 class="method" id="method_viewmodel">viewmodel($view, $method = 'view', $aut
<th><kbd>$view</kbd></th>
<td><em>string</em></td>
<td><pre class="php"><code>null</code></pre></td>
<td class="description">The viewmodel name. See the <a href="../../general/viewmodels.html">Viewmodel</a> for more information.</td>
<td class="description">The presenter name. See the <a href="../../general/presenters.html">Presenter</a> for more information.</td>
</tr>
<tr>
<th><kbd>$method</kbd></th>
<td><em>string</em></td>
<td><pre class="php"><code>'view'</code></pre></td>
<td class="description">name of the method in the Viewmodel instance that will be called to process the data prior to rendering the view.</td>
<td class="description">name of the method in the Presenter instance that will be called to process the data prior to rendering the view.</td>
</tr>
<tr>
<th><kbd>$auto_filter</kbd></th>
Expand All @@ -291,7 +291,7 @@ <h4 class="method" id="method_viewmodel">viewmodel($view, $method = 'view', $aut
</tr>
<tr>
<th>Returns</th>
<td>A new <em>ViewModel</em> object</td>
<td>A new <em>Presenter</em> object</td>
</tr>
<tr>
<th>Throws</th>
Expand All @@ -304,11 +304,11 @@ <h4 class="method" id="method_viewmodel">viewmodel($view, $method = 'view', $aut
$theme = \Theme::instance();

/**
* with the default settings, will load the ViewModel defined in
* with the default settings, will load the Presenter defined in
* APPPATH.'classes/view/template/homepage.php', using the
* THEMEDIR.'/template/homepage.php' view file
*/
$viewmodel = $theme->viewmodel('template/homepage');
$presenter = $theme->presenter('template/homepage');
</code></pre>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion general/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h3 id="config">Configuration options</h3>
<td><pre class="php"><code>array(
'stdClass',
'Fuel\\Core\\View',
'Fuel\\Core\\ViewModel',
'Fuel\\Core\\Presenter',
'Closure'
)</code></pre></td>
<td>
Expand Down
31 changes: 1 addition & 30 deletions general/controllers/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,36 +117,7 @@ <h4 id="controller_in_subdir">Controllers in Sub-Directories</h4>

<h4 id="controller_namespacing">Namespacing controllers</h4>

<p>
As mentioned in the introduction by default controllers are created in the <kbd>app/classes/controller</kbd> folder,
and are prefixed with <var>Controller_</var>. This prefix is defined in your <kbd>app/config/config.php</kbd> configuration file
(and if not this is the default), but can be changed if you want to namespace your controllers, or if you
want to move them to a different folder structure.
</p>

<p>
Lets move the example given above to the <kbd>Controller</kbd> namespace. You tell FuelPHP that you've done this by setting the
config setting <var>controller_prefix</var> from <kbd>'Controller_'</kbd> to <kbd>'Controller\\'</kbd> in your app's config.php file.
</p>

<pre class="php"><code>namespace Controller;

class Example extends \Controller
{

public function action_index()
{
$data['css'] = Asset::css(array('reset.css','960.css','main.css'));
return Response::forge(View::forge('welcome/index'));
}
}</code></pre>

<p class="note">
Note that now that your controller lives in a namespace, you have to prefix "Controller" with a backslash, since it needs to be
loaded from the global namespace.
</p>


<p>See the page on <a href="../namespacing.html">namespacing</a> to see how you can namespace your controllers</p>

<h4 id="more_parameters">Using more parameters from the URL</h4>

Expand Down
4 changes: 2 additions & 2 deletions general/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ <h4 id="404_handling">404 handling</h4>
$data['title'] = $messages[array_rand($messages)];

// Set a HTTP 404 output header
return Response::forge(View::forge('welcome/404', $data), 404);
return Response::forge(Presenter::forge('welcome/404', $data), 404);
}</code></pre>

<p>
Expand All @@ -159,7 +159,7 @@ <h4 id="404_handling">404 handling</h4>
</p>

<p class="note">
Note that Fuel doesn't set the 404 status, your response must set this. Return <em>Response::forge(ViewModel::forge('welcome/404'), 404);</em>
Note that Fuel doesn't set the 404 status, your response must set this. Return <em>Response::forge(Presenter::forge('welcome/404'), 404);</em>
in order to send the correct status header.
</p>

Expand Down
2 changes: 1 addition & 1 deletion general/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h3 id="module_namespace">Module namespace</h3>
</code></pre>

<p class="note">
If you have moved your controllers into a namespace like it is explained <a href="./controllers/base.html#/controller_namespacing">here</a>, you have to use
If you have moved your controllers into a namespace like it is explained <a href="./namespacing.html#controllers">here</a>, you have to use
the same setup for your module controllers. In this example the namespace will be <var>Mymodule\Controller</var>, the classname <var>Widget</var>.
</p>

Expand Down
12 changes: 6 additions & 6 deletions general/mvc.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h3 id="what_is_mvc">What is MVC?</h3>

<h3 id="controllers">Controllers</h3>

<p>Controllers are located in <kbd>APPPATH/classes/controller</kbd></p>
<p>Controller classes are located in <kbd>APPPATH/classes/controller</kbd></p>

<p>Fuel's routing decides based on the requested URL what controller to load and what method to call upon it.
This is where your application starts working. The Controller decides what actions to take, what to do with any
Expand All @@ -66,7 +66,7 @@ <h3 id="controllers">Controllers</h3>

<h3 id="models">Models</h3>

<p>Models are located in <kbd>APPPATH/classes/model</kbd></p>
<p>Model classes are located in <kbd>APPPATH/classes/model</kbd></p>

<p>Whenever data needs to be retrieved, manipulated or deleted this should always be done by a model. A Model
is a representation of some kind of data and has the methods to change them. For example: you never put SQL
Expand All @@ -89,16 +89,16 @@ <h3 id="views">Views</h3>

<p>Read more about <a href="views.html">Views</a>.</p>

<h3 id="viewmodels">Viewmodels</h3>
<h3 id="presenters">Presenters</h3>

<p>Viewmodels are located in <kbd>APPPATH/classes/view</kbd></p>
<p>Presenter classes are located in <kbd>APPPATH/classes/presenter</kbd></p>

<p>Once your application gets more complex you'll discover that it gets hard to decide if a piece of logic
really belongs in the Controller, what if it is very specifically about the View and has little to do with your
application logic? This is where ViewModels come in; they are the glue between your controllers and your
application logic? This is where Presenters come in; they are the glue between your controllers and your
views.</p>

<p>Read more about <a href="viewmodels.html">Viewmodels</a>.</p>
<p>Read more about <a href="presenters.html">Presenters</a>.</p>

</div>

Expand Down
Loading

0 comments on commit 6c3b4a0

Please sign in to comment.