Welcome Guest, Not a member yet? Register   Sign In
Validation callback in a CI package
#11

[eluser]Johnny Freeman[/eluser]
I agree. Since it's a MojoMotor Addon I'd rather not have any MM hacks in there (by extending one of it's controllers). I want ALL of the addon's code to be contained within the third_party folder.

Any word on whether or not extending libraries inside a package is possible?
#12

[eluser]kenny.katzgrau[/eluser]
In /system/core/Loader.php:_ci_load_class(), CodeIgniter will only check the application/libraries and system/libraries directories when loading classes.

So in short, not yet. But it's something that should actually be added by the next release.

But once we do that, we should really think about full-blown HMVC.
#13

[eluser]Johnny Freeman[/eluser]
[quote author="kenny.katzgrau" date="1296880098"]But once we do that, we should really think about full-blown HMVC.[/quote]

Would definitely be nice! You have my vote.

Thanks for your help!
#14

[eluser]wiredesignz[/eluser]
@johnny Freeman, Extend the Form_Validation library and add your callbacks as native validation methods. I'm surprised our "Engineers" haven't suggested this.

I also have a full blown HMVC setup working with MojoMotor if you are interested. Email me.
#15

[eluser]Johnny Freeman[/eluser]
@wiredesignz - Thanks for the suggestion. However, I am making this MM addon to distribute and I do not want to require others to extend their MM installation in order to use my addon. Or is that kind of thing typical of MM addons?
#16

[eluser]wiredesignz[/eluser]
@johnny Freeman, In your package then create a library that includes (requires) and extends the CI_Form_Validation class and name the class and its file something like "Validation" in "package_name/libraries/Validation.php"

Place your callback methods therein.

Then load your Validation library and use it as if it were native, and use your own callback methods accordingly.
#17

[eluser]Johnny Freeman[/eluser]
Ahh, nice idea! Maybe you could show me a simple code example of how I would load the new validation class and then an example of how I could leverage it. Thanks!
#18

[eluser]Johnny Freeman[/eluser]
I'm guessing I would just put this at the top of my form library:
Code:
require('validation.php');

Then load it in the process() method (the method that we'll be doing the form validation in) like this:
Code:
$validation = new validation();

Or is there a better way? some php5 way that I'm not aware of yet?
#19

[eluser]wiredesignz[/eluser]
Something like:

package_name/libraries/Validation.php
Code:
<?php

require BASEPATH.'libraries/Form_validation.php';

class Validation extends CI_Form_Validation {

    /* validation method */
    public function some_method() {

    }
}

Add the package to your application then load the Validation library containing your validation methods.
Code:
$CI = CI_Controller::get_instance();

$CI->load->library('validation');

$CI->validation->run();

Your methods won't be callbacks. They will be called as native form validation methods.
#20

[eluser]Johnny Freeman[/eluser]
Thanks, I think this is probably the best solution for what I need. I'll try it out first thing monday.




Theme © iAndrew 2016 - Forum software by © MyBB