Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created July 12, 2012 18:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/3099863 to your computer and use it in GitHub Desktop.
Save zanematthew/3099863 to your computer and use it in GitHub Desktop.
Sample auto loader
<?php
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
* the dir.
*/
$tmp_controllers = scandir( CONTROLLERS_ROOT_DIR );
array_shift( $tmp_controllers ); // shift off .
array_shift( $tmp_controllers ); // shift off ..
foreach( $tmp_controllers as $controller ) {
/**
* autoload Controllers
*/
require_once CONTROLLERS_ROOT_DIR . $controller;
// Return just the first part of our controller
$name = array_shift( explode( '_', $controller ) );
/**
* Models
*/
if ( file_exists( MODELS_ROOT_DIR . $name . '.php' ) )
require_once MODELS_ROOT_DIR . $name . '.php';
$date = date('F j, Y, g:i a');
/**
* Add our stylesheets to our global array
*/
if ( file_exists( CSS_ROOT_DIR . $name . '.css' ) ) {
$_styles[] = CSS_DIR . $name . '.css';
} else {
@file_put_contents( CSS_ROOT_DIR . $name . '.css', "/* This automatically created for you. \n It is your css file for the {$name} model, controller \n Created On: {$date} */");
}
/**
* Add our javascript to our global array
*/
if ( file_exists( JS_ROOT_DIR . $name . '.js' ) ) {
$_scripts[] = JS_DIR . $name . '.js';
} else {
@file_put_contents( JS_ROOT_DIR . $name . '.js', "/* This automatically created for you. \n It is your js file for the {$name} model, controller \n Created On: {$date} */");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment