Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Cannot use form validation library?
#1

[eluser]Jason Stanley[/eluser]
This error is so dumb it hurts. I have poked my code and I can see no error.

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Categories::$form_validation

Filename: admin/categories.php

Line Number: 23

Backtrace:

File: C:\xampp\htdocs\blog\application\controllers\admin\categories.php
Line: 23
Function: _exception_handler

File: C:\xampp\htdocs\blog\index.php
Line: 251
Function: require_once

Now...
1) Form validation works fine on another controller thus it exists etc
2) If I modify the form validation library to print something in the constructor that thing is printed. I.e. the script is loaded.
3) If I print_r($this), form_validation shows up as a loaded library but not as a class in the controller.

Code:
<?php
class Categories extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->model('categories_model');
  $this->load->library('form_validation');
  $this->load->helper('form');
}

public function create()
{
  if ( $this->input->post('create'))
  {
   if ($this->form_validation->run('admin/categories/create')) // Line 23

Any ideas?
#2

[eluser]Jason Stanley[/eluser]
Update.

Moving the library above the model fixes the error.

Code:
<?php
class Categories extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->library('form_validation');
  $this->load->model('categories_model');
  $this->load->helper('form');
}

However error messages are not displaying.

Code:
function form_error($field = '', $prefix = '', $suffix = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{ echo 2;
  return '';
}

return $OBJ->error($field, $prefix, $suffix);
}

Always prints 2. But... if I print_r the validation object after validation...

Quote:[_error_array:protected] => Array
(
[title] => The Title field is required.
)

That to me looks like there is an error... i'm a bit lost.
#3

[eluser]Jason Stanley[/eluser]
...

Model was extending CI_Controller instead of CI_Model. Apparently this makes really funky things happen.




Theme © iAndrew 2016 - Forum software by © MyBB