• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions can't be called from libraries.

#3
[eluser]TheFuzzy0ne[/eluser]
By default, CodeIgniter checks in 2 places for callbacks -- Your controller, and the validation class itself. If you have your callbacks anywhere else, you will either need to modify the form validation class, or you will need to add an alias method to either the form validation class or your controller. I think the best option is to have a separate version of the form validation class for each "section" of your Web site. For example, one for user validation, one for product validation and so on. Then you can simply load the class you need, and all of the relevant methods are there.

./application/libraries/Product_validation.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include BASEPATH . 'libraries/Form_validation' . EXT;

class Product_validation extends CI_Form_validation {
    protected $CI;

    function __construct()
    {
        parent::__construct();
        
        $this->CI =& get_instance();
    }

    public function valid_product_class($class)
    {
        $this->CI->load->model('model_products');
        
        if( ! $this->CI->model_products->check_class($class))
        {
            $this->set_message('valid_product_class', 'Invalid class');
            return FALSE;
        }
        
        return TRUE;
    }
}

So from your controller:
Code:
$this->load->library('product_validation');

$this->product_validation->set_rules(
        'class',
        'Product Class',
        'numeric|xss_clean|valid_product_class'
    );

if ($this->form_validation->run())
{
    // WOOHOO!!!
}

// D'OH!

Hope this helps.


Messages In This Thread
Functions can't be called from libraries. - by El Forum - 05-06-2013, 03:49 PM
Functions can't be called from libraries. - by El Forum - 05-07-2013, 02:51 AM
Functions can't be called from libraries. - by El Forum - 05-07-2013, 06:30 AM
Functions can't be called from libraries. - by El Forum - 05-07-2013, 07:57 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.