Ticket #446 (closed Feature Request: wontfix)

Opened 9 months ago

Last modified 5 months ago

Template View

Reported by: allain Owned by: - No owner -
Priority: minor Milestone: 2.2
Component: Libraries Version: SVN HEAD
Keywords: template view Cc:

Description

Let me start by saying I like the Template_Controller class. I've been using it for a bit now. I just find using it a little verbose, and on the conceptual level I didn't like the Controller being modified to support something that just "feels" like it should be in the view.

The following code is my attempt at an alternative way of doing things, which I think is a little cleaner.

<?php
class Template_View_Core extends View_Core {
	public function __construct($view_file, $template_file='templates/default') {
		parent::__construct($template_file);
		$this->content_view = new View($view_file);
	}
	
	public function __set($field_name, $value) {
		$this->data['content_view']->$field_name = $value;

		return parent::__set($field_name, $value);
	}
}
?>

And you would use it in the controller like this:

public function welcome() {
   $view = new Template_View('welcome');
   $view->message = 'Hello World';
   $view->title = 'Welcome Page';
   $view->render(TRUE);
}

With the following in application/views/templates/default.php:

<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1><?=$title?></h1>
<?=$content_view?>
</body>
</html>

And this in application/views/welcome.php:

<p>We've provided this message for you: <strong><?=$message?></strong></p>

If this has merit I think it could be extended to allow for multiple subviews (named of course) without too much extra work.

Change History

Changed 5 months ago by Geert

Scratching my head. Actually I like the Template_Controller as it currently is and I am wondering whether something less transparent like Template_View is really needed.

What I don't like anyway is that Template_View_Core->_set() sets all variables to both the template and the content view. Namespace clutter? Moreover, we have View_Core->set_global() available already to solve that problem.

Personally I prefer creating an abstract Website_Controller that extends Template_Controller. In the Website_Controller you load some global libraries, models and initialize some view variables like $pagetitle. Your regular Page_Controllers then extend the Website_Controller. It has all the functionality I need. I guess you even could integrate your own custom template_view() method in there.

So, I will not close this ticket for now. Would be nice to get some more user input, but personally I am going to have to vote against a Template_View class because I fail to see the added value. Never the less, thanks.

Changed 5 months ago by Shadowhand

  • status changed from new to closed
  • resolution set to wontfix

Good idea for a custom View extension, but doesn't really make sense as a core library.

Note: See TracTickets for help on using tickets.