我创建了一个输入脚本。我将名字和脚本帖子名称写入数据库。但我有错误 - ErrorException [ Notice ]: Undefined variable: result
。为什么我会收到错误:未定义的变量?
有我的控制器:
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';
}
}
还有就是我的观点:
<form action="">
<input type="text" name="name" />
</form>
而且是我的模型:
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));
}
}
问题出在哪里?
编辑#1
我编辑控制器:
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';
}
}
但这不工作,因为当我输入名字,他们没有付诸数据库。
谢谢!但是这个脚本不起作用,因为当我提交一个名字时,脚本不会把名字放入数据库中。 – reGative