Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3

[eluser]Daeli[/eluser]
Hey there,

got a huge problem Sad

Look at this. Iam loading a module over my uri:

Code:
$module = $this->uri->segment(1, "welcome");
    $method = $this->uri->segment(2, "index");
    $args = array_slice($this->uri->segment_array(), 2);
    
    $this->load->module($module);

...some lines later i load the content into my template container:

Code:
$content['main'] = $this->$module->$method($args);

Now when i try to load validation library inside my module controller i get an error:

Fatal error: Call to a member function set_rules() on a non-object in C:\workspace\capitalo\system\application\modules\user\controllers\user.php on line 18

Module controller is stored under:
Application
-Modules
--User
---Controllers
----user.php

Here is the Module Controller code:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
Class User extends Controller{
    function __construct()
    {
        parent::Controller();
    }
    
    function login(){
        $this->assetlib->load('mootools', 'js');
        $this->assetlib->load('common', 'js');
        
        $this->lang->load('user');
        $this->load->library('validation');
            
        $rules['user_name']    = "required";
        $rules['user_pass']    = "required";
        
        $this->validation->set_rules($rules);
        
        if($this->validation->run() == FALSE)
            return $this->load->view('login', null, TRUE);
    }
    
    function register(){
        
    }
}
?>

[eluser]wiredesignz[/eluser]
Hey Daeli, Well I added your validation setup code to a module controller and it works fine.
You may have a non fatal error being generated before the library is loaded, which is causing it not to load properly. Try loading the library earlier and see if the error changes.

[eluser]Daeli[/eluser]
I can load the library in the constructor. But not in the login function.

[eluser]wiredesignz[/eluser]
I was able to load and run your code from both the constructor and inside a method. There may be other errors that aren't showing up. Try turning CI logging on to its highest level and check there.

[eluser]Daeli[/eluser]
Hmm no errors there...

Code:
DEBUG - 2008-07-13 15:01:19 --> Config Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Hooks Class Initialized
DEBUG - 2008-07-13 15:01:19 --> URI Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Router Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Output Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Input Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Global POST and COOKIE data sanitized
DEBUG - 2008-07-13 15:01:19 --> Language Class Initialized
DEBUG - 2008-07-13 15:01:19 --> MainController Controller Initialized
DEBUG - 2008-07-13 15:01:19 --> Loader Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Config file loaded: config/capitalo.php
DEBUG - 2008-07-13 15:01:19 --> Helpers loaded: url
DEBUG - 2008-07-13 15:01:19 --> Language file loaded: language/english/navigation_lang.php
DEBUG - 2008-07-13 15:01:19 --> Language file loaded: language/english/common_lang.php
DEBUG - 2008-07-13 15:01:19 --> Database Driver Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Session Class Initialized
DEBUG - 2008-07-13 15:01:19 --> Helpers loaded: debug_helper
DEBUG - 2008-07-13 15:01:19 --> File loaded: C:\workspace\capitalo/system/application/modules/user/controllers/user.php
DEBUG - 2008-07-13 15:01:19 --> User Controller Initialized
DEBUG - 2008-07-13 15:01:19 --> File loaded: C:\workspace\capitalo/system/application/modules/controls/controllers/navigationcontrol.php
DEBUG - 2008-07-13 15:01:19 --> NavigationControl Controller Initialized
DEBUG - 2008-07-13 15:01:19 --> File loaded: C:\workspace\capitalo/system/application/modules/controls/controllers/usercontrol.php
DEBUG - 2008-07-13 15:01:19 --> UserControl Controller Initialized
DEBUG - 2008-07-13 15:01:19 --> Language file loaded: language/english/user_lang.php
DEBUG - 2008-07-13 15:01:19 --> Validation Class Initialized
ERROR - 2008-07-13 15:01:19 --> Severity: Notice  --> Undefined property:  User::$validation C:\workspace\capitalo\system\application\modules\user\controllers\user.php 15

[eluser]wiredesignz[/eluser]
Ok I see the problem, because CI assigns the last controller as the value for get_instance, and CI_Loader uses get_instance to load system libraries, validation has been assigned to usercontrol.php rather than user.php

You need to load libraries in the constructor of your module controllers to avoid this.

[eluser]Daeli[/eluser]
Oh thats kinda bad you know Smile

[eluser]Chicken's Egg[/eluser]
Hé wiredesignz, I see you've found the new wiki-pages I made. Smile I see you've also improved my code example at the FAQ-page. Sadly the new code gives me an error. "Only variable references should be returned by reference. Filename: libraries/Controller.php. Line Number: 294." That is why I had written a TRUE behind the view and a return. Otherwise I don't know how to display it correctly.
And it looks like you didn't like my 'Notices and errors' very much. I'm sorry for that, I did my best. :down:

[eluser]wiredesignz[/eluser]
@Daeli, It's due to the fact that CI prevents us altering codeigniter/Base4.php or Base5.php and uses get_instance() when loading libraires rather than passing a reference to the loader. Note: This only happens with CI system/libraries.

@Chicken's Egg, I updated the wiki Errors page because there was information not relevant to ME, Thanks for your efforts though they are appreciated.

[eluser]wiredesignz[/eluser]
Modular Extensions version 4.2.05 (bugfix) is available on the wiki.

Fixed: “Only variable references should be returned by reference" error. Thanks Chicken's Egg. Wink




Theme © iAndrew 2016 - Forum software by © MyBB