Yehonatan

view

Jul 31st, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.     class view
  3.     {
  4.         protected $view_name;
  5.         protected $view_items;
  6.         protected $view_path;
  7.         protected $data;
  8.        
  9.         //Set the view directory
  10.         public function set_view($directory)
  11.         {
  12.             $this->view_name = $directory;
  13.             $this->view_path = dirname(__FILE__) . "/views/" . $directory;
  14.             $this->view_items = scandir($this->view_path);
  15.         }
  16.        
  17.         //Add data to view data
  18.         public function add_data($name = null, $data)
  19.         {
  20.             $this->data[$name] = $data;
  21.             return true;
  22.         }
  23.        
  24.         //Remove data by selected key name or key data
  25.         public function remove_data($key_name = null, $key_data = null)
  26.         {
  27.             $new_data = array();
  28.            
  29.             foreach($this->data as $key => $data)
  30.             {
  31.                 if($data != $key_data && $key != $key_name)
  32.                     $new_data[$key] = $data;
  33.             }
  34.             $this->data = $new_data;
  35.             return true;
  36.         }
  37.        
  38.         public function clear_data()
  39.         {
  40.             $this->data = null;
  41.             return true;
  42.         }
  43.        
  44.        
  45.         //Include the view item selected, requires view item name and data
  46.         public function loadSelected($name, $suffix = null)
  47.         {
  48.             if($suffix == null)
  49.                 include($this->view_path . "/" . $name . ".php");
  50.             else
  51.                 include($this->view_path . "/" . $name . $prefix);
  52.         }
  53.        
  54.     }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment