Welcome Guest, Not a member yet? Register   Sign In
Functions can't be called from libraries.
#1

[eluser]behnampmdg3[/eluser]
Hello;

In the example below I want to keep my controller small so I keep all my validations in another place. Well I think a good way would be to keep them in libraries/my_functions. But for some reason I cannot call any functions from libraries/my_functions.

In the example I can easily call validate_search() from my controller but I cannot call any functions from there (from my_functions)!

For example the callback function callback_valid_product_class below doesnt work, or test() does not work either.

2 questions:

1 - Why cant I call these functions?
2 - Is this the proper way of keeping controller light?

Thank you

Controller:
Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Products extends CI_Controller {

public function search()
{
  if(!$this->input->post('submit'))
   {
    redirect(base_url('products'), 'location', 301);
   }
  $this->load->library('my_functions');
  
  

  
  if($this->my_functions->validate_search()) //Works fine
   {
    echo 'valid';
   }
  else
   {
    $this->show_form();
    $this->right_column_and_footer();
   }
  
}
}
my_functions.php
Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_functions {

  
public function validate_search()
  {
   $CI =& get_instance();
   $CI->form_validation->set_rules('class', 'Product Class', 'numeric|xss_clean|callback_valid_product_class');
   if ($CI->form_validation->run() == FALSE)
    {
     return FALSE;
    }
   else
    {
     return TRUE;
    }
  
  }
public function valid_product_class($class)
   {
    exit();
    $CI->load->model('model_products');
    if($CI->model_products->check_class($class))
     {
      return true;
     }
    else
     {
      $CI->form_validation->set_message('class', 'Invalid class');
      return FALSE;
     }
   }
        $CI->test();
        public function test()
                 {
                       echo "Hi";
                 }
}


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



Theme © iAndrew 2016 - Forum software by © MyBB