new with codeigniter - El Forum - 04-14-2011
[eluser]InsiteFX[/eluser]
Show your code where the error is!
InsiteFX
new with codeigniter - El Forum - 04-14-2011
[eluser]danmontgomery[/eluser]
The error messages tell you exactly what line the error is on, you can't do any debugging at all?
new with codeigniter - El Forum - 04-14-2011
[eluser]kiga[/eluser]
this is the code, i'm trying to debug something, but this is my first time with codeigniter and php
Code: function add(){
// set validation properties
$this->_set_fields();
// set common properties
$data['title'] = 'Add new person';
$data['message'] = '';
$data['action'] = site_url('person/addPerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
// load view
$this->load->view('personEdit', $data);
}
function addPerson(){
// set common properties
$data['title'] = 'Add new person';
$data['action'] = site_url('person/addPerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
// set validation properties
$this->_set_fields();
$this->_set_rules();
// run validation
if ($this->validation->run() == FALSE){
$data['message'] = '';
}else{
// save data
$person = array('name' => $this->input->post('name'),
'gender' => $this->input->post('gender'),
'dob' => date('Y-m-d', strtotime($this->input->post('dob'))));
$id = $this->personModel->save($person);
// set form input name="id"
$this->validation->id = $id;
// set user message
$data['message'] = '<div class="success">add new person success</div>';
}
// load view
$this->load->view('personEdit', $data);
}
Code: function update($id){
// set validation properties
$this->_set_fields();
// prefill form values
$person = $this->personModel->get_by_id($id)->row();
$this->validation->id = $id;
$this->validation->name = $person->name;
$_POST['gender'] = strtoupper($person->gender);
$this->validation->dob = date('d-m-Y',strtotime($person->dob));
// set common properties
$data['title'] = 'Update person';
$data['message'] = '';
$data['action'] = site_url('person/updatePerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
// load view
$this->load->view('personEdit', $data);
}
new with codeigniter - El Forum - 04-14-2011
[eluser]InsiteFX[/eluser]
So where is this function?
Code: $this->_set_fields();
InsiteFX
new with codeigniter - El Forum - 04-14-2011
[eluser]kiga[/eluser]
is this
Code: // validation fields
function _set_fields(){
$fields['id'] = 'id';
$fields['name'] = 'name';
$fields['gender'] = 'gender';
$fields['dob'] = 'dob';
$this->validation->_set_fields($fields);
}
// validation rules
function _set_rules(){
$rules['name'] = 'trim|required';
$rules['gender'] = 'trim|required';
$rules['dob'] = 'trim|required|callback_valid_date';
$this->validation->set_rules($rules);
$this->validation->set_message('required', '* required');
$this->validation->set_message('isset', '* required');
$this->validation->set_error_delimiters('<p class="error">', '</p>');
}
new with codeigniter - El Forum - 04-14-2011
[eluser]InsiteFX[/eluser]
_set_fields is from the old validation Class and is removed for new CI version!
Here is what you need to do Read the CodeIgniter User Guide - Form_Validation and Form_helper
All your code needs to be converted to the new Form_Vlaidation Class.
There is nothing else here that we can do for you!
InsiteFX
new with codeigniter - El Forum - 04-14-2011
[eluser]kiga[/eluser]
i try to change the validation to form_validation
Code: // validation fields
function _set_fields(){
$fields['id'] = 'id';
$fields['name'] = 'name';
$fields['gender'] = 'gender';
$fields['dob'] = 'dob';
$this->form_validation->_set_fields($fields);
}
// validation rules
function _set_rules(){
$rules['name'] = 'trim|required';
$rules['gender'] = 'trim|required';
$rules['dob'] = 'trim|required|callback_valid_date';
$this->form_validation->set_rules($rules);
$this->form_validation->set_message('required', '* required');
$this->form_validation->set_message('isset', '* required');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
}
// date_validation callback
function valid_date($str)
{
if(!ereg("^(0[1-9]|1[0-9]|2[0-9]|3[01])-(0[1-9]|1[012])-([0-9]{4})$", $str))
{
$this->form_validation->set_message('valid_date', 'date format is not valid. dd-mm-yyyy');
return false;
}
else
{
return true;
}
}
but i still have something wrong
( ! ) Fatal error: Call to undefined method CI_Form_validation::_set_fields() in C:\wamp\www\CodeIgniter\application\controllers\person.php on line 177
Call Stack
# Time Memory Function Location
1 0.0933 386312 {main}( ) ..\index.php:0
2 0.6529 454800 require_once( 'C:\wamp\www\CodeIgniter\system\core\CodeIgniter.php' ) ..\index.php:201
3 1.1664 3229184 call_user_func_array ( ) ..\CodeIgniter.php:339
4 1.1664 3229232 Person->add( ) ..\CodeIgniter.php:0
5 1.1664 3229232 Person->_set_fields( ) ..\person.php:57
this is the line
Code: function add(){
// set validation properties
$this->_set_fields();
// set common properties
$data['title'] = 'Add new person';
$data['message'] = '';
$data['action'] = site_url('person/addPerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
// load view
$this->load->view('personEdit', $data);
}
new with codeigniter - El Forum - 04-15-2011
[eluser]InsiteFX[/eluser]
Well it's up to you now!
Read the CodeIgniter User Guide like I said.
Also Learn how to debug you application.
Every error you have shown gives you the error message and the line number were the error is at.
We are not going to re-write the application for you!
InsiteFX
|