Welcome Guest, Not a member yet? Register   Sign In
Need Help With Modular Extensions
#1

[eluser]php_wizardry[/eluser]
Ok, I have installed ME and trying to build a modular CMS. However, things aren't going well for me. Here are the errors I have:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Admin::$parser

Filename: MX/Loader.php

Line Number: 143
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Theme_module::$theme_model

Filename: controllers/theme_module.php

Line Number: 19

Fatal error: Call to a member function get_page_info() on a non-object in C:\xampp\htdocs\cms\system\application\modules\theme\controllers\theme_module.php on line 19

I am trying to load the info as I normally would with CI such as:$this->load->library('parser'); and $this->load->model('theme/theme_model');

Can anyone please tell me what I am doing wrong. I am pretty sure this is allowed from what I have read in the docs. Thanks.
#2

[eluser]wiredesignz[/eluser]
Post some code man, the errors means nothing without seeing your code.
#3

[eluser]php_wizardry[/eluser]
Here is the controller calling the theme module:
Code:
<?php
session_start();
class Admin extends Controller{

    function __construct(){
        parent::__construct();
        $this->load->helper('url');
    }
    
    function index(){
        //Lets load modules
        $this->load->module('auth/auth_module');
        if($this->auth_module->check_login()==FALSE){
            $this->login();
        }
    }
    
    function login(){
        $this->load->module('auth/auth_module');
        $this->load->module('theme/theme_module');
        
        //Lets check if user is logged in
        if($this->auth_module->check_login()==FALSE){
            $data=array(
                'site_base_url'=>base_url()
            );
            $this->theme_module->build('default', 'login_template.htm', 'admin-login');
            
        }
    }
    
}
?>

Then here is the controller for the theme module
Code:
<?php
class Theme_module extends Controller{

    //Load some default values
    function __construct()
    {
        parent::__construct();
        $this->load->helper('file');
        $this->load->helper('url');
    }

    
    function build($theme='default', $layout='default.php', $slug='home'){
        $this->load->library('parser');
        $this->load->model('theme/theme_model');
        
        
        //Lets grab the page and its info from db
        $page_info=$this->theme_model->get_page_info($slug);
        
        //Lets get the css style pages
        $css_pages='<style type="text/css">';
        $css_files=get_filenames('system/application/views/'.$theme.'/css', TRUE);
        foreach($css_files as $css){
            $css_pages.=read_file($css);
        }
        $css_pages.="</style>";
        
        //Lets setup the variables for page
        if(count($page_info)>0){
            $meta_description=$page_info['meta_description'];
            $meta_keywords=$page_info['meta_keywords'];
            $meta_title=$page_info['meta_title'];
            $css=$page_info['css'];
            $js=$page_info['js'];
            $title=$page_info['title'];
            $body=$page_info['body'];
        }else{
            $meta_description='';
            $meta_keywords='';
            $meta_title='';
            $css='';
            $js='';
            $title='';
            $body='';
        }
        
        //Put data together
        $data=array(
            "meta_description"=>$meta_description,
            "meta_keywords"=>$meta_keywords,
            "meta_title"=>$meta_title,
            "css_pages"=>$css_pages,
            "css"=>$css,
            "js"=>$js,
            "title"=>$title,
            "body"=>$body
        );
        
        $this->parser->parse($theme.'/'.$layout, $data);
    }
}
?>

Then the model for the theme module
Code:
<?php
    class Theme_model extends Model{
        
        function __construct(){
            parent::__construct();
        }
        
        function get_page_info($slug){
            $this->load->library('database');
            $slug=$this->db->escape($slug);
            $get_page_info_query="SELECT * FROM `pages` WHERE `slug`=".$slug;
            $get_page_info_result=$this->db->query($get_page_info_query);
            return $get_page_info_result->row_array();
        }
    
    }
?>
#4

[eluser]wiredesignz[/eluser]
Ok you are using HMVC features of Modular Extensions by loading modules so your controllers need to extend the MX_Controller class. Try that first.
#5

[eluser]php_wizardry[/eluser]
Extending the MX_Controller on the theme module controller, I now get this error: Fatal error: Cannot redeclare class CI in C:\xampp\htdocs\cms\system\application\third_party\MX\Base.php on line 76. BTW, thanks for the help. Wink
#6

[eluser]wiredesignz[/eluser]
Extend MX_Contoller in all controllers. You're not even loading a module in the Theme controller. You are in the Admin controller.
#7

[eluser]php_wizardry[/eluser]
Smile you are the man. If I am not mistaken, you are the guy that created this? Also, I thought you only had to extend the MX_Controller if you were like viewing the module by the URL? Anyways, thanks for helping me out and creating the kewl module lib. Smile
#8

[eluser]wiredesignz[/eluser]
No worries. You must extend MX_Controller whenever loading modules or using modules::run
#9

[eluser]php_wizardry[/eluser]
Also, what do you mean by not loading a module in theme? theme is the module. am I not using the way this was intended? pretty much what I wanted to do, was create a cms that uses modules so that I could drop modules in and then a coder/user could integrate the module into the cms pretty easily. Not exactly plug n play but more of using a cms to customize an already built module. Smile
#10

[eluser]wiredesignz[/eluser]
I meant the main controller (Admin) needs to extend MX_Controller more so than the module controller itself. You had it backwards for a moment by extending the Theme controller and not Admin.

The main controller needs to be able to locate the module controller properly and MX_Controller allows this. It does not hurt to always extend MX_Controller in any case.




Theme © iAndrew 2016 - Forum software by © MyBB