$this->ci->load->module($this->module)->load->config('auth', TRUE); $this->ci->load->module($this->module)->load->config('auth', TRUE); $this->ci->load->config('auth', TRUE); $config = $this->ci->load->config('auth'); <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* PHP5 spl_autoload */
spl_autoload_register('modules::load');
spl_autoload_register('modules::autoload'); include_once('system/libraries/MY_Router.php'); <?php
class Texts extends Controller {
function index($id) {
echo 'text';
$this->load->models('mtexts');
echo $this->mtexts->getText($id);
}
}
?>
<?php
class Mtexts extends Model {
function Mtexts() {
parent::Model();
}
function getText($id) {
$query = $this->db->query(select * from....);
$res = $query->row();
return $res->text;
}
}
?>
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: libraries/Controller.php
Line Number: 244
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$mtexts
Filename: libraries/Controller.php
Line Number: 378
Fatal error: Call to a member function getText() on a non-object in Z:hometest4.ruwwwsystemapplicationmodulestextscontrollerstexts.php on line 10
if($class = self::load($module.'/'.$controller)) {
if (method_exists($class, $method)) {
ob_start();
$args = func_get_args();
$output = call_user_func_array(array($class, $method), array_slice($args, 1));
$buffer = ob_get_clean();
return ($output) ? $output : $buffer;
}
if($class = self::load($module.'/'.$controller)) {
if(method_exists($class, '_remap')){
ob_start();
$args = func_get_args();
$output = call_user_func_array(array($class, '_remap'), array($args));
$buffer = ob_get_clean();
return ($output) ? $output : $buffer;
}
if (method_exists($class, $method)) {
ob_start();
$args = func_get_args();
$output = call_user_func_array(array($class, $method), array_slice($args, 1));
$buffer = ob_get_clean();
return ($output) ? $output : $buffer;
}
Tovit писал(а):...но нужен ли повторный роутинг в пределах модуля? И выполнить его, по сути, не сложно, но отвечает ли это логике такой архитектуры?
Для меня модуля в веб-приложении -- это самостоятельные сегменты системы.
class module extends Controller {
var $_controller = '';
var $_folder = APPPATH;
var $_ci = null;
function _assign_libraries() {
foreach (array_keys(get_object_vars($this)) as $key) {
if ((isset($this->_ci->$key) === false) && (strcasecmp('module', $key) !== 0)) {
$this->_ci->$key = null;
$this->_ci->$key = & $this->$key;
}
}
}
function _remap($method) {
$segments = array_slice($this->uri->rsegments, 1);
$segments = $this->_locate_controller($segments);
$filename = $this->_folder.'controllers/'.$this->_controller.EXT;
if (is_file($filename) === false) {
show_404();
}
$this->_create_controller();
if (count($segments) > 0) {
$method = $segments[0];
$segments = array_slice($segments, 1);
} else {
$method = 'index';
}
$this->_execute_controller($method, $segments);
}
function _get_folder($folder) {
return $this->_folder . 'modules/' . $folder.'/';
}
function _set_folder($folder) {
$this->_folder = $this->_get_folder($folder);
}
function _locate_controller($segments) {
foreach($segments as $segment) {
$folder = preg_replace('/^([^\-]+?)-.*$/', '$1', $segment);
$file = preg_replace('/^.*?-([^\-]+)$/', '$1', $segment);
$this->_controller = $file;
$this->_set_folder($folder);
$segments = array_slice($segments, 1);
$s = $this->_locate_subcontroller($folder, $segments);
if ($s === false) {
break;
} else {
$segments = $s;
}
}
return $segments;
}
function _locate_subcontroller($folder, $segments) {
$foldername = $this->_get_folder($folder);
if (is_dir($foldername) === true) {
$segments = array_slice($segments, 1);
$segments = $this->_set_folder($folder, $segments);
$this->_controller = $file;
return $segments;
}
return false;
}
function _create_controller() {
$filename = $this->_folder.'controllers/'.$this->_controller.EXT;
$class_name = $this->_controller;
include_once($filename);
if (class_exists($class_name) === false) {
show_error('Class ' . $class_name . ' is not found in controller.');
}
$this->_ci = new $class_name($this->_module);
$this->_assign_libraries();
}
function _execute_controller($method, $segments) {
if (method_exists($this->_ci, '_remap') === true) {
$this->_ci->_remap($method);
}
if (method_exists($this->_ci, $method) === false) {
show_error('Method ' . $method . ' is not exists in controller.');
}
call_user_func_array(array($this->_ci, $method), $segments);
}
}
Tovit писал(а):могли бы и сюда решение разместить -- может кто другой не спрашивал бы.
$this->ci =& get_instance(); $this->ci = Modules::load('auth'); <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class news extends Controller {
function __construct(){
parent::__construct();
}
function index(){
$this->load->view('news_main_tpl', null);
}
function widget($news_count = 1){
$this->load->view('news_widget_tpl', null);
}
} class main extends Controller {
function __construct(){
parent::__construct();
}
function index(){
$this->module('news');
$this->load->view('main_tpl');
}
}
<html>
<head>
</head>
<body>
<p>Главный шаблон</p>
<div>Контент</div>
<div><?php echo modules::run('news/widget'); ?></div>
</body>
$route['(.+)'] = 'welcome/$1'; Tovit писал(а):В главном роутинге:
- Код: Выделить всё
$route['(.+)'] = 'welcome/$1';
Tovit писал(а):А дальше -- анализируете uri через _remap($first_segment).
Вернуться в Решения, авторский код и библиотеки
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 0