Welcome Guest, Not a member yet? Register   Sign In
Modular Separation - PHP5 (Modules)

[eluser]Keat Liang[/eluser]
here is my codes, i made a simple example,

Code:
/application/modules/welcome/controllers/welcome.php
/application/modules/welcome/views/welcome_view.php

tested with follow link with no problem
Code:
index.php/welcome
index.php/welcome/put
index.php/welcome/get


here is the code
Code:
<?php

class Welcome extends Controller {

    function __construct()
    {
        parent::Controller();
                $this->load->library('session');
    }
    
    function index()
    {
        $this->load->view('welcome/welcome_view');
    }
    
    function put()
    {
        $this->session->set_userdata(array('some_key' => 'some_val'));
    }
    
    function get()
    {
        echo $this->session->userdata('some_key');
    }
}

problem start here from another module

Code:
/application/modules/hello/controllers/hello.php
/application/modules/hello/views/world_view.php

here is the controller code

Code:
class hello extends Controller
{

    function __construct()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->view('hello/world_view');
    }
    
    function nolib()
    {
        //this work
        echo Modules::run('welcome/welcome/index') . '<br/ >';
    }
    
    function withlib()
    {
        //not working
        echo Modules::run('welcome/welcome/put') . '<br/ >';
    }
    
    function withlib2()
    {
        //not working either
        echo Modules::run('welcome/welcome/get') . '<br/ >';
    }
    
    function withlib3()
    {
        //not working either
        $this->load->module('welcome/welcome');
        echo $this->welcome_welcome->method() . '<br />';
    }
}

when i try to extend MX_Controller
Code:
class hello extends MX_Controller
{

    function __construct()
    {
        parent::MX_Controller();
    }

    function index()
.........

and i get this.....

Code:
Call to undefined method MX_Controller::MX_Controller()

one more question if i wanna use this Extension, can i still using Base controller similar to MY_Controller ?

MY_Controller.php

i try modify to this
Code:
&lt;?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* The MX_Controller class is autoloaded as required */
class MY_Controller extends MX_Controller{
    function __construct()
    {
        parent::MX_Controller();
    }
}

then the controller extends from MY_Controller not working too... i try everything i know still nothing come out. any help will be appreciated.

sorry for my bad english.

[eluser]wiredesignz[/eluser]
@Keat Liang, Your controllers must extend the MX_Controller class.

[eluser]Keat Liang[/eluser]
[quote author="wiredesignz" date="1289934832"]@Keat Liang, Your controllers must extend the MX_Controller class.[/quote]

i get this when i did that (any link or functions)
Code:
Fatal error: Call to undefined method MX_Controller::MX_Controller() in D:\EasyPHP-5.3.3.1\www\HMVC\application\modules\hello\controllers\hello.php on line 8


welcome.php
Code:
&lt;?php

class Welcome extends MX_Controller {

    function __construct()
    {
        parent::MX_Controller();
        $this->load->library('session');
    }
    
    function index()
    {
        $this->load->view('welcome/welcome_view');
    }
    
    function put()
    {
        $this->session->set_userdata(array('some_key' => 'some_val'));
    }
    
    function get()
    {
        echo $this->session->userdata('some_key');
    }
}

hello.php
Code:
&lt;?php

class hello extends MX_Controller
{

    function __construct()
    {
        parent::MX_Controller();
    }

    function index()
    {
        $this->load->view('hello/world_view');
    }
    
    function nolib()
    {
        //this work
        echo Modules::run('welcome/welcome/index') . '<br/ >';
    }
    
    function withlib()
    {
        //not working work
        echo Modules::run('welcome/welcome/put') . '<br/ >';
    }
    
    function withlib2()
    {
        //not working work either
        echo Modules::run('welcome/welcome/get') . '<br/ >';
    }
    
    function withlib3()
    {
        //not working work either
        $this->load->module('welcome/welcome');
        echo $this->welcome_welcome->method() . '<br />';
    }
    

    
    
}

anything i done wrong ?

[eluser]wiredesignz[/eluser]
Use PHP5 constructors.
Code:
&lt;?php
class Xyz extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
    }
}

[eluser]Keat Liang[/eluser]
[quote author="wiredesignz" date="1289935869"]Use PHP5 constructors.[/quote]

YAY !!! thx it's working, thanks a lot man !

thanks for patient with me.

one more question.

i can get this work under hello.php

Code:
function withlib3()
    {
        //yay! it's working
        $this->load->module('welcome');
        echo $this->welcome->get() . '<br />';
    }

when i made some changes to test the example given in bitbucket wiki like the following

Code:
function withlib3()
    {
        //not working :(
        /*
          $this->load->module(’module/controller’);
          $this->module_controller->method()
        */
        $this->load->module('welcome/welcome');
        echo $this->welcome_welcome->get() . '<br />';
    }

i get this error

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI::$welcome_welcome

Filename: MX/Controller.php

Line Number: 57


Fatal error: Call to a member function get() on a non-object in D:\EasyPHP-5.3.3.1\www\HMVC\application\modules\hello\controllers\hello.php on line 42

[eluser]wiredesignz[/eluser]
The Bitbucket wiki example was incorrect and has been updated.

[eluser]Keat Liang[/eluser]
[quote author="wiredesignz" date="1289977414"]The Bitbucket wiki example was incorrect and has been updated.[/quote]

Everything working ! thumbs up !, Wiki is updated YAY!!! hope it help others too. :lol:

[eluser]umefarooq[/eluser]
hi im trying Modular extension with CI2 but getting this error

Code:
Fatal error: Class 'CI_Controller' not found in C:\AppServ\www\ci2\application\third_party\MX\Ci.php on line 40

[eluser]wiredesignz[/eluser]
CI 2.0 has been altered to use a CI_Controller class.

[eluser]By AzraiL[/eluser]
php 5.3.0 not working hmvc, blank page Sad php 5.2.9 or php 5.3.3 working.




Theme © iAndrew 2016 - Forum software by © MyBB