Last active
December 30, 2015 00:09
-
-
Save enov/7747957 to your computer and use it in GitHub Desktop.
How I use WinterSilence / kohana-meta-tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This works because we are rendering the content first | |
Meta::instance()->title('Home'); | |
?> | |
Welcome to the Home Page! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Controller_Page extends Controller { | |
public function action_page() | |
{ | |
$page = $this->request->param('page'); | |
if (Kohana::find_file('views', $page) === FALSE) | |
{ | |
throw new HTTP_Exception_404('The requested page :page could not be found', array( | |
':page' => $page, | |
)); | |
} | |
$content = View::factory($page)->render(); // be careful to render before template | |
$template = View::factory('template'); | |
$template->set('content', $content); | |
$this->response->body($template); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<?= Meta::instance()->render()?> | |
</head> | |
<body> | |
<?=$content?> | |
</body> | |
</html> | |
I understand your concern. However, Welcome to the Home Page! is also some kind of data, right? Yet, it's hard-coded in view...
So why not have some pragmatism and add the title in the same file as content, since they are very related?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/enov/7747957#file-home-php-L4 here in violation of the concept of mvc - you set data in view