I created an input script. I write name and script post name into database. But I have error - ErrorException [ Notice ]: Undefined variable: result
.
There
Possibly because an empty value was passed to name
and the variable doesn't get initialized unless its non-empty. But it gets used in the following line, outside the if
$this->template->content = View::factory('about/about')->set('result', $result);
Initialize $result
outside the if()
:
$result = "";
if(!empty($_POST['name'])){
$name = Model::factory('index')->insert_names($_POST['name']);;
$result= $name;
}
Or move the entire block that follows the if(){}
inside it.
public function action_index()
{
if(!empty($_POST['name'])){
$name = Model::factory('index')->insert_names($_POST['name']);;
$result= $name;
// move this inside the if()
$this->template->site_name = Kohana::$config->load('common')->get('site_name');
$this->template->site_description = Kohana::$config->load('common')->get('site_description');
$this->template->page_title = 'About';
$this->template->content = View::factory('about/about')->set('result', $result);
$this->template->styles[] = 'index/index';
}
}