Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
I don't know if I'm having a brain fart, or if I just don't know how to accomplish this... I would like to restrict a method's access to member variables and other methods. For example... I have a render() method in a View class (yes, this is for my Calendar if you're wondering) and I would like to make sure it doesn't have access to variables it doesn't need look at my comment inside of the render() class...
<?php
class MC2_Calendar_View_Template extends MC2_Calendar_View{
protected $template;
protected $data = array();
public function __construct($template=null){
if(!is_null($template)) $this->template = $template;
}
public function setTemplate($template){
$this->template = $template;
}
public function assign($key, $value){
$this->data[$key] = $value;
}
public function render(){
/* This is the area I am talking about. Do you see how I only am giving the template
access to specific variables? How do I restrict this access so that you can't just grab
variables by $this->calendar->month->fullName() from within the template? */
// Assign allowed variables from month and calendar
$grid = $this->calendar->getGrid();
$month = $this->calendar->month->fullName();
$week = $this->calendar->week;
$totalDays = $this->calendar->month->totalDays();
// Extract the user-supplied data
extract($this->data);
// Render the template
ob_start();
include $this->template;
return ob_get_clean();
}
}
?>
If you do not want the view properties and methods available you should probably make you template a separate class rather than extending the View. I usually composite the Template within the View for this reason.