<span class="preprocessor"><?php</span>
<span class="keyword">class</span> Homepage <span class="keyword">extends</span> \Controller
{
<span class="comment">/**
* load the theme template, set the page title and the menu's
*/</span>
<span class="keyword">public</span> <span class="keyword">function</span> before()
{
<span class="comment">// load the theme template</span>
<span class="variable">$this</span>->theme = \Theme::instance();
<span class="comment">// set the page template</span>
<span class="variable">$this</span>->theme->set_template(<span class="string">'layouts/homepage'</span>);
<span class="comment">// set the page title (can be chained to set_template() too)</span>
<span class="variable">$this</span>->theme->get_template()->set(<span class="string">'title'</span>, <span class="string">'My homepage'</span>);
<span class="comment">// set the homepage navigation menu</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'navbar'</span>, <span class="string">'homepage/navbar'</span>);
<span class="comment">// define chrome with rounded window borders for the sidebar section</span>
<span class="variable">$this</span>->theme->set_chrome(<span class="string">'sidebar'</span>, <span class="string">'chrome/borders/rounded'</span>, <span class="string">'partial'</span>);
<span class="comment">// set the partials for the homepage sidebar content</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'sidebar'</span>, <span class="string">'homepage/widgets/login'</span>);
<span class="variable">$this</span>->theme->set_partial(<span class="string">'sidebar'</span>, <span class="string">'homepage/widgets/news'</span>)->set(<span class="string">'users'</span>, Model_News::latest(<span class="number">5</span>));
<span class="comment">// call the user model to get the list of logged in users, pass that to the users sidebar partial</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'sidebar'</span>, <span class="string">'homepage/widgets/users'</span>)->set(<span class="string">'users'</span>, Model_User::logged_in_users());
}
<span class="comment">/**
* A simple example. A normal action method would probably have code to
* retrieve data from models and pass this to a partial view...
*/</span>
<span class="keyword">public</span> <span class="keyword">function</span> action_index()
{
<span class="comment">// the homepage has a flash image banner</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'banner'</span>, <span class="string">'homepage/banner'</span>);
<span class="comment">// a block of static content</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'banner'</span>, <span class="string">'homepage/content'</span>);
<span class="comment">// and two link lists and a copyright block</span>
<span class="variable">$this</span>->theme->set_partial(<span class="string">'footerleft'</span>, <span class="string">'homepage/shortcuts'</span>);
<span class="variable">$this</span>->theme->set_partial(<span class="string">'footercenter'</span>, <span class="string">'homepage/links'</span>);
<span class="variable">$this</span>->theme->set_partial(<span class="string">'footerright'</span>, <span class="string">'homepage/copyright'</span>);
}
<span class="comment">/**
* keep the after() as standard as possible to allow custom responses from actions
*/</span>
<span class="keyword">public</span> <span class="keyword">function</span> after(<span class="variable">$response</span>)
{
<span class="comment">// If no response object was returned by the action,</span>
<span class="keyword">if</span> (<span class="keyword">empty</span>(<span class="variable">$response</span>) <span class="keyword">or</span> ! <span class="variable">$response</span> instanceof Response)
{
<span class="comment">// render the defined template</span>
<span class="variable">$response</span> = \Response::forge(\Theme::instance()->render());
}
<span class="keyword">return</span> <span class="keyword">parent</span>::after(<span class="variable">$response</span>);
}
}
Don't change the after methods, you have to modify only the before and index method:It looks like you're new here. If you want to get involved, click one of these buttons!