Skip to content

Instantly share code, notes, and snippets.

@thiagosf
Created November 21, 2010 17:42
Show Gist options
  • Save thiagosf/708944 to your computer and use it in GitHub Desktop.
Save thiagosf/708944 to your computer and use it in GitHub Desktop.
Arquivo de erro para facilitar na criação de arquivos de controle para CakePHP
<h2><?php __('Missing Controller'); ?></h2>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__('%s could not be found.', true), "<em>" . $controller . "</em>");?>
</p>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo sprintf(__('Create the class %s below in file: %s', true), "<em>" . $controller . "</em>", APP_DIR . DS . "controllers" . DS . Inflector::underscore($controller) . ".php");?>
</p>
<pre>
&lt;?php
class <?php echo $controller;?> extends AppController {
var $name = '<?php echo $controllerName;?>';
}
?&gt;
</pre>
<p class="notice">
<strong><?php __('Notice'); ?>: </strong>
<?php echo sprintf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . "views" . DS . "errors" . DS . "missing_controller.ctp");?>
</p>
<?php
// Criando arquivo autmaticamente
if (isset($_GET['auto'])) {
$valor = "<?php
class {$controller} extends AppController {
var \$name = '{$controllerName}';
// é
function index () {
}
}
?>";
$name = '..' . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php';
if (!is_file($name)) {
$fp = fopen($name, 'a');
fwrite($fp, utf8_encode($valor));
fclose($fp);
echo '<p><a href="">Arquivo criado com sucesso!</a></p>';
}
}
else {
$name = '..' . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php';
if (!is_file($name)) {
echo '<p><a href="?auto=true">Criar aquivo</a></p>';
}
}
// Fim da criação do arquivo
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment