2011-07-11 117 views
1

控制器:插入值,Zend框架沒有工作

<?php 
class AdminController extends Zend_Controller_Action 
{ 
    public function init() 
    { 
     error_reporting(E_ALL); 
    } 

    public function indexAction() 
    { 
     // blank // 
    } 

    public function registerAction() 
    { 
     // database configuration // 
     $config = array(
      'host' => 'localhost', 
      'username' => 'root', 
      'password' => '', 
      'dbname' => 'zendfirst' 
     ); 
     $db = new Zend_Db_Adapter_Pdo_Mysql($config); 

     // get request(get/post) // 
     $request = $this->getRequest();  

     if($request->isPost('fsubmit')) { 
      $insert_data = array(
       'first_name' => $request->first_name, 
       'last_name' => $request->last_name 
      ); 
      $db->insert('admin', $insert_data); 
     } 
    } 
} 

查看:

<form method="post" action=""> 

    <div class="form_div"> 
     <label for="first_name">First Name</label> 
     <input type="text" value="" name="first_name" id="first_name" />  
    </div> 

    <div class="form_div"> 
     <label for="last_name">Last Name</label> 
     <input type="text" value="" name="last_name" id="last_name" /> 
    </div> 

    <div class="form_div"> 
     <input type="submit" value="Register" name="fsubmit" id="fsubmit" /> 
    </div> 

</form> 

<style> 
.form_div { 
    padding : 5px; 
} 
</style> 

設置 「的php.ini」

extension=php_pdo_mysql.dll 

數據庫表:

admin_id first_name last_name 
-------- ---------- --------- 

引發錯誤

An error occurred 
Application error 

問題是什麼? Zend Framework中是否有像CodeIgniter這樣的「profiler」?

+0

後容易它是這樣的 - 你發現一些作品,然後將它符合您的需要 – Ulterior

+0

您可以發佈全異常堆棧跟蹤 –

回答

0

您正在將帖子值視爲一個對象。試試這個:

public function registerAction() 
    { 
     // database configuration // 
     $config = array(
      'host' => 'localhost', 
      'username' => 'root', 
      'password' => '', 
      'dbname' => 'zendfirst' 
     ); 
     $db = new Zend_Db_Adapter_Pdo_Mysql($config); 

     // get request(get/post) // 
     $request = $this->getRequest();  

     if($request->isPost('fsubmit')) { 
      $post_data = $request->getPost(); 
      $insert_data = array(
       'first_name' => $post_data['first_name'], 
       'last_name' => $post_data['last_name'] 
      ); 
      $db->insert('admin', $insert_data); 
     } 
    }