Permalink
Browse files

Allow model aliasing in controllers

  • Loading branch information...
1 parent 2a9a6be commit 3a9b184ddf71403e0de977dc066e7c48618417b0 @Breefield committed Oct 27, 2010
Showing with 13 additions and 3 deletions.
  1. +4 −2 crumb/MVC/class.controller.php
  2. +2 −1 crumb/MVC/class.crumbMVC.php
  3. +7 −0 crumb/MVC/class.mimeType.php
@@ -45,14 +45,16 @@ public function __tail() {
* property name
* @param string $model The name of the model
*/
- public function load($model) {
+ public function load($model, $name = null) {
global $APP_MODELS;
try {
/* Include the model first */
$this->includeModel($model, $APP_MODELS, true);
$model = $this->getPieceName($model);
/* Then instantiate it */
- $this->$model = new $model;
+ if($name == null) $name = $model;
+ else $name = $name;
+ $this->$name = new $model;
} catch(Exception $e) {
throw $e;
}
@@ -228,7 +228,8 @@ public function loadSupport($file) {
/* read the file off, this prevents against the browser
* prompting a download
*/
- readfile($file);
+ if(!mimeType::isTextType($mime_type)) readfile($file);
+ else require_once($file);
exit();
}
}
@@ -89,10 +89,17 @@ public function getMimeType($filename) {
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
+ } elseif(function_exists('system')) {
+ $type = system(trim('file -bi '.escapeshellarg($f)));
+ return $type;
} else {
/* Otherwise, let the browser guess */
return 'application/octet-stream';
}
}
+
+ public function isTextType($type) {
+ return in_array($type, array('text/html', 'text/css', 'application/javascript'));
+ }
}
?>

0 comments on commit 3a9b184

Please sign in to comment.