Welcome Guest, Not a member yet? Register   Sign In
form_validation in dev version and HMVC, problem with callback.
#1

[eluser]letsgolee[/eluser]
First, please forgive me if there is any poor english.

I changed wiredesignz's HMVC a little to make it work with 3.0 dev version and these are the changes:

1. The routine of _set_default_controller() in core/Router.php has been changed. So I copied the function code to MX/Router.php and commented some lines of the function codes.
Code:
protected function _set_default_controller()
{
  if (empty($this->default_controller))
  {
   show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
  }

  // Is the method being specified?
  if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
  {
   $method = 'index';
  }
/** For 3.0-dev
  if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
  {
   // This will trigger 404 later
   return;
  }
*/
  $this->set_class($class);
  $this->set_method($method);

  // Assign routed segments, index starting from 1
  $this->uri->rsegments = array(
   1 => $class,
   2 => $method
  );

  log_message('debug', 'No URI present. Default controller set.');
}
2. added a line(s) in MX/Loader.php for the loading of any library class. I think it's a kind of bug. It is in library() function.
Code:
if ($path === FALSE) {
  
   $this->_ci_load_class($library, $params, $object_name);
   $_alias = $this->_ci_classes[$class];

   /** For 3.0-dev **/
   CI::$APP->$_alias = $this->$class;
  } else {

and it has been working fine with 3.0 dev except one thing so far. if Form_validation has any rule with callback then CI gives an error message that the callback function cannot be found, but the callback function is inside the controller class. So I figured that the form_validation->CI and CI::$APP are not the same. To solve the problem, I changed the access modifier of CI_Form_validation::CI from "protected" to "public" and after loading form_validation, set form_validation->CI to $this, so the code is like:
Code:
$this->load->library('form_validation');
$this->form_validation->CI =& $this;
Then callback function can be called. But I want to know a more decent method. Thanks in advance.
#2

[eluser]letsgolee[/eluser]
Never mind!!! I found my way. I made MY_Form_validation.php in application/libraries

Code:
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {
function __construct()
{
  parent::__construct();
}

function set_modular_ci(& $ci)
{
  $this->CI =& $ci;
}
}

Sorry for bothering you. I just started to use codeigniter 6 months ago and still I'm learning how to extend the core...




Theme © iAndrew 2016 - Forum software by © MyBB