Hi I got the following error when I first run this page, but it becomes alright once you click submit on the form.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$error
Filename: character/create.php
Line Number: 49Here’s the controller
function slot($slot)
{
$this->validation->set_error_delimiters('<div id="error">', '</div>');
$rules['display_name'] = "xss_clean";
$fields['display_name'] = 'Display Name';
$this->validation->set_rules($rules);
$this->validation->set_fields($fields);
//list of classes
$data['class'] = array('archer'=>'Archer', 'warrior'=>'Warior');
//create character
$display_name = $this->input->post('display_name');
$c = '';
switch($this->input->post('class'))
{
case 'archer':
$c = new Archer();
break;
case 'warrior':
$c = new Warrior();
break;
}
$c->display_name = $display_name;
$c->hp = 100;
$c->time_created = time();
if ($this->validation->run() && $c->save())
{
echo "Character created!";
}
else
{
if (interface_exists($c->error)) {echo 'true'; } else { echo 'false';}
$this->load->view('character/create_view', $data);
}
}The model:
<?php
class Archer extends DataMapper {
var $has_many = array("archer_skill" => "archer_skills");
var $has_one = array("battle" => "battles", 'player' => 'players');
var $validation = array(
array(
'field' => 'display_name',
'label' => 'Display Name',
'rules' => array('trim', 'required', 'min_length' => 4, 'max_length' => 15, 'alpha_dash', 'unique')
),
);
function Archer()
{
parent::DataMapper();
}
}
?>I have tried different ways to check if $c->error->string is present but couldn’t find a way because it always has the same error of undefined stdclass.
Is there any way to check if stdClass::$error is defined?
Thank you!