Created
June 5, 2013 14:51
-
-
Save MauMaGau/5714446 to your computer and use it in GitHub Desktop.
Sublime CI module controller snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class $1_module extends MX_Controller { | |
private \$called_from_url = FALSE; | |
public function __construct() | |
{ | |
\$this->load->model('$1_module/$1_model'); | |
} | |
public function _remap(\$method, \$params) | |
{ | |
\$this->called_from_url = TRUE; // this module has been accessed directly from the url, not from code | |
/* Do not allow direct access via URL unless the method is listed in the site config */ | |
if (in_array(\$method, \$this->config->item('$1_module', 'allowed_module_methods'))){ | |
return call_user_func_array(array(\$this, \$method), \$params); | |
} | |
show_404(); | |
} | |
public function __call(\$method, \$params) | |
{ | |
/* Pass 'direct-access' methods to the module model */ | |
if( ! method_exists(\$this, \$method)){ | |
if(method_exists(\$this->$1_model, \$method)){ | |
return call_user_func_array(array(\$this->$1_model, \$method), \$params); | |
} | |
} | |
} | |
public function single_view(\$view='debug', \$object_type, \$object_id) | |
{ | |
\$data = array(); | |
switch(\$view){ | |
default: | |
if(\$this->input->is_ajax_request() && \$this->called_from_url){ | |
header('Content-type: application/json'); | |
echo json_encode( array('html' => \$this->load->view('page_elements/$1/single/'.\$view, \$data, TRUE) ) ); | |
}else{ | |
\$this->load->view('page_elements/$1/single/'.\$view, \$data); | |
} | |
break; | |
} | |
} | |
} | |
/* End of file $1_module.php */ | |
/* Location: ./application/modules/$1_module/controllers/$1_module.php */ | |
]]></content> | |
<tabTrigger>module</tabTrigger> | |
<scope>source.php, text.html.basic, text.plain</scope> | |
<description>CI - Module Controller</description> | |
</snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment