class Controller_Media extends Kohana_Controller{ public function action_index($path, $file) { $this->request->check_cache(sha1($this->request->uri)); // media/css media/js .css .js , = if($path == 'css' || $path == 'js') { $ext = $path; } else { $ext = pathinfo($file, PATHINFO_EXTENSION); $file = substr($file, 0, -(strlen($ext) + 1)); } // View::GetTplName() , - default, , views/default/media/... - View::GetTplName() . if ($file = Kohana::find_file('views/'.View::GetTplName().'/media/'.$path, $file, $ext)) { // , $this->request->response = file_get_contents($file); // $this->request->headers['Content-Type'] = File::mime_by_ext($ext); $this->request->headers['Content-Length'] = filesize($file); $this->request->headers['Last-Modified'] = date('r', filemtime($file)); } else { // 404, $this->request->status = 404; } } }
Route::set('media', 'media/<path>/<file>', array('file' => '.*')) ->defaults(array( 'controller' => 'media', 'action' => 'index' ));
Source: https://habr.com/ru/post/104862/
All Articles