Changeset 2005 for trunk/application/controllers/examples.php
- Timestamp:
- 02/09/2008 12:07:53 AM (11 months ago)
- Files:
-
- 1 modified
-
trunk/application/controllers/examples.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/controllers/examples.php
r2004 r2005 73 73 ); 74 74 75 $view = $this->load->view('viewinview/container', $data);76 $view->header = $this->load->view('viewinview/header', $data);75 $view = new View('viewinview/container', $data); 76 $view->header = new View('viewinview/header', $data); 77 77 78 78 $view->render(TRUE); … … 98 98 function session() 99 99 { 100 $s = new Session(); 100 // Gets the singleton instance of the Session library 101 $s = Session::instance(); 101 102 102 103 echo 'SESSID: <pre>'.session_id()."</pre>\n"; … … 112 113 function form() 113 114 { 114 $ this->load->library('validation');115 $validation = new Validation; 115 116 116 117 echo form::open('', array('enctype' => 'multipart/form-data')); … … 126 127 if ( ! empty($_POST)) 127 128 { 128 $ this->validation->set_rules('imageup', 'required|upload[gif,png,jpg,500K]', 'Image Upload');129 echo '<p>validation result: '.var_export($ this->validation->run(), TRUE).'</p>';130 } 131 132 echo Kohana::debug($ this->validation);129 $validation->set_rules('imageup', 'required|upload[gif,png,jpg,500K]', 'Image Upload'); 130 echo '<p>validation result: '.var_export($validation->run(), TRUE).'</p>'; 131 } 132 133 echo Kohana::debug($validation); 133 134 echo Kohana::lang('core.stats_footer'); 134 135 } … … 149 150 ); 150 151 151 // Same as CI, but supports passing an array to the constructor 152 $this->load->library('validation', $data); 152 $validation = new Validation($data); 153 153 154 154 // Looks familiar... 155 $ this->validation->set_rules(array155 $validation->set_rules(array 156 156 ( 157 157 // Format: … … 163 163 164 164 // Same syntax as before 165 $ this->validation->run();165 $validation->run(); 166 166 167 167 // Same syntax, but dynamcially generated wth __get() 168 echo $ this->validation->error_string;168 echo $validation->error_string; 169 169 170 170 // Yay! … … 193 193 function database() 194 194 { 195 $this->load->database(); 195 $db = new Database; 196 196 197 $table = 'pages'; 197 198 echo 'Does the '.$table.' table exist? '; 198 if ($ this->db->table_exists($table))199 if ($db->table_exists($table)) 199 200 { 200 201 echo '<p>YES! Lets do some work =)</p>'; 201 202 202 $query = $ this->db->select('DISTINCT pages.*')->from($table)->get();203 echo $ this->db->last_query();203 $query = $db->select('DISTINCT pages.*')->from($table)->get(); 204 echo $db->last_query(); 204 205 echo '<h3>Iterate through the result:</h3>'; 205 206 foreach($query as $item) … … 208 209 } 209 210 echo '<h3>Numrows using count(): '.count($query).'</h3>'; 210 echo 'Table Listing:<pre>'.print_r($ this->db->list_tables(), TRUE).'</pre>';211 echo 'Table Listing:<pre>'.print_r($db->list_tables(), TRUE).'</pre>'; 211 212 212 213 echo '<h3>Try Query Binding with objects:</h3>'; 213 214 $sql = 'SELECT * FROM '.$table.' WHERE id = ?'; 214 $query = $ this->db->query($sql, array(1));215 echo '<p>'.$ this->db->last_query().'</p>';215 $query = $db->query($sql, array(1)); 216 echo '<p>'.$db->last_query().'</p>'; 216 217 $query->result(TRUE); 217 218 foreach($query as $item) … … 222 223 echo '<h3>Try Query Binding with arrays (returns both associative and numeric because I pass MYSQL_BOTH to result():</h3>'; 223 224 $sql = 'SELECT * FROM '.$table.' WHERE id = ?'; 224 $query = $ this->db->query($sql, array(1));225 echo '<p>'.$ this->db->last_query().'</p>';225 $query = $db->query($sql, array(1)); 226 echo '<p>'.$db->last_query().'</p>'; 226 227 $query->result(FALSE, MYSQL_BOTH); 227 228 foreach($query as $item) … … 231 232 232 233 echo '<h3>Look, we can also manually advance the result pointer!</h3>'; 233 $query = $ this->db->select('title')->from($table)->get();234 $query = $db->select('title')->from($table)->get(); 234 235 echo 'First:<pre>'.print_r($query->current(), true).'</pre><br />'; 235 236 $query->next(); … … 241 242 echo 'Rewound:<pre>'.print_r($query->current(), true).'</pre>'; 242 243 243 echo '<p>Number of rows using count_records(): '.$ this->db->count_records('pages').'</p>';244 echo '<p>Number of rows using count_records(): '.$db->count_records('pages').'</p>'; 244 245 } 245 246 else … … 256 257 function pagination() 257 258 { 258 $ this->pagination = new Pagination(array(259 $pagination = new Pagination(array( 259 260 // 'base_url' => 'welcome/pagination_example/page/', // base_url will default to current uri 260 261 'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality … … 265 266 266 267 // Just echoing it is enough to display the links (__toString() rocks!) 267 echo 'Classic style: '.$ this->pagination;268 echo 'Classic style: '.$pagination; 268 269 269 270 // You can also use the create_links() method and pick a style on the fly if you want 270 echo '<hr />Digg style: '.$ this->pagination->create_links('digg');271 echo '<hr />Extended style: '.$ this->pagination->create_links('extended');272 echo '<hr />PunBB style: '.$ this->pagination->create_links('punbb');271 echo '<hr />Digg style: '.$pagination->create_links('digg'); 272 echo '<hr />Extended style: '.$pagination->create_links('extended'); 273 echo '<hr />PunBB style: '.$pagination->create_links('punbb'); 273 274 echo 'done in {execution_time} seconds'; 274 275 } … … 279 280 function user_agent() 280 281 { 281 $ this->load->library('user_agent');282 $ua = new User_agent; 282 283 283 284 foreach(array('agent', 'browser', 'version') as $key) 284 285 { 285 echo $key.': '.$ this->user_agent->$key.'<br/>'."\n";286 echo $key.': '.$ua->$key.'<br/>'."\n"; 286 287 } 287 288
