Welcome Guest, Not a member yet? Register   Sign In
set_value returns always default value
#1

[eluser]Unknown[/eluser]
Hello,

I encountered the following problem on PHP Version 5.2.17, on my others servers (PHP 5.2.6 and PHP/5.3.10) the problem doesn't exists!

I have a simple controller:
Code:
function test()
{
  $data = array('test' => NULL);
  $this->form_validation->set_rules('test', '', 'trim|xss_clean|required');
  if ($this->form_validation->run()) {
    $data['test'] = $this->form_validation->set_value('test');
  }
  $data['result'] = array('valuebydatabase' => 'lorem');
  $this->load->view('test', $data);
}

A simple view:

Code:
<?=form_open(current_url());?>
<?php
// For debugging
echo $test;
?>

<input type="text" name="test" id="test" value="<?=set_value('test', $result['valuebydatabase']);?>">

<input type="submit" name="sbm" value="Submit" />

<?=form_close();?>


On my Server running PHP 5.2.17 the input value is always "lorem" although I post another value, on the other servers I get the right value...

I think PHP is initalizing a new object instead of using the existing object.

Wwhen I was debbugging the form_helper, the rules were no more in the object (View -> Calls helper -> Helper gets the instance of the object)! ->
$OBJ =& _get_validation_object() (This should be equal with $this->form_validation).

Inside the controller the rules were given and also "$this->form_validation->set_value('test');" got the right value....

So why this special PHP-Version gets not the right value?!


#2

[eluser]Unknown[/eluser]
I'm debbuging now the problem on both servers and found the source of the problem:

In the form_helper.php the server tries to get a new instance:
$CI =& get_instance(); -> Alias for: CI_Controller::get_instance()

On the one server we have the rules set in this object, on the others not!

So we are now in the core file:
Code:
/**
* CodeIgniter Application Controller Class
*
* This class object is the super class that every library in
* CodeIgniter will be assigned to.
*
* @package  CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author  ExpressionEngine Dev Team
* @link  http://ellislab.com/codeigniter/user-guide/general/controllers.html
*/
class CI_Controller {

private static $instance;

/**
  * Constructor
  */
public function __construct()
{
  self::$instance =& $this;

  // Assign all the class objects that were instantiated by the
  // bootstrap file (CodeIgniter.php) to local class variables
  // so that CI can run as one big super object.
  foreach (is_loaded() as $var => $class)
  {
   $this->$var =& load_class($class);
  }

  $this->load =& load_class('Loader', 'core');

  $this->load->initialize();

  log_message('debug', "Controller Class Initialized");
}

public static function &get;_instance()
{
  return self::$instance;
}
}
// END Controller class

/* End of file Controller.php */
/* Location: ./system/core/Controller.php */

But I have no idea why the one PHP-Version gives me with return self::$instance; the right object and the other one a new object?
#3

[eluser]Aken[/eluser]
You should never receive a NEW CodeIgniter object. That's the whole purpose of the singleton pattern.

It sounds like you're experiencing the problem on one server but not another. Meaning it's likely an environment issue. Try to find what's different between the two. I tested your code and it worked fine.




Theme © iAndrew 2016 - Forum software by © MyBB