我創建了一個輸入腳本。我將名字和腳本帖子名稱寫入數據庫。但我有錯誤 - 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