I created an input script. I write name and script post name into database. But I have error – ErrorException [ Notice ]: Undefined variable: result .
There is my controller:
class Controller_About extends Controller_Template{
public function action_index()
{
if(!empty($_POST['name'])){
$name = Model::factory('index')->insert_names($_POST['name']);;
$result= $name;
}
$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';
}
}
There is my view:
<form action="">
<input type="text" name="name" />
</form>
And the is my model:
Class Model_Index Extends Model {
public static function insert_names($name){
$query = DB::query(DATABASE::INSERT, 'INSERT INTO names (name) VALUES (:name)')->parameters(array(':name' => $name));
}
}
Where is the problem?
Edit #1
I edited the controller:
class Controller_About extends Controller_Template{
public function action_index()
{$result = '';
if(!empty($_POST['name'])){
$name = Model::factory('index')->insert_names($_POST['name']);;
$result= $name;
}
$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';
}
}
But this not working, because when I input name, they not puts into database.
Possibly because an empty value was passed to
nameand the variable doesn’t get initialized unless its non-empty. But it gets used in the following line, outside theifInitialize
$resultoutside theif():Or move the entire block that follows the
if(){}inside it.