2014-01-07 24 views
0

我收到意外的异常。当我更新这样的数据:在PDO方法中找不到异常类

try { 
    $restaurantUpd = new Restaurant(); 
    $restaurantUpd->updateRestaurant(array('restaurant_name' => Input::get('restaurant_name'), 
              'restaurant_location' => Input::get('restaurant_location'), 
              'restaurant_contact_email' => Input::get('restaurant_contact_email') 
             ), $_GET['edit']); 
    //ok 
} catch(Exception $e) { 
    die($e->getMessage()); 
} 

它返回此错误: Warning: require_once(classes/Exeption.php): failed to open stream: No such file or directory in C:\xampp\htdocs\admintest\core\init.php on line 32

但奇怪的是我没有Exeption.php类?此外,第32行是指我自动加载:

/* 
* Autoload function for classes 
*/ 
spl_autoload_register(function($class) { 
    require_once 'classes/' . $class . '.php'; 
}); 

在餐厅类我更新的方法是这样的...

public function updateRestaurant($fields = array(), $id = null) { 
    if (!$this->_db->update('rt_restaurant', $id, $fields, false)) { 
     throw new Exeption('There was a problem updating'); 
    } 
} 

,并从DB类的更新方法PDO准备,执行,取

任何指导?

+4

'Exeption'表明可能有一个错字 –

+0

spl_autoload_register尝试需要一个文件,如果没有找到这个类,在你的程序中,它试图寻找异常类被称为在CATCH,也许你正在使用旧版本的PHP。请告诉您的PHP版本,并检查它是否有异常类... –

+0

我的PHP版本ID是最新的... PHP版本5.4.22 – rZaaaa

回答

0

这是在类方法

public function updateRestaurant($fields = array(), $id = null) { 
    if (!$this->_db->update('rt_restaurant', $id, $fields, false)) { 
     throw new Exeption('There was a problem updating'); 
    } 
} 

另外一个错字...抛出,原因是在德DB方法的错误,我选择了例外whas WHERE id = $ ID

但是在MySQL中它没有被叫做id,但是rest_id。

0

你有拼写错误 ExeptionException在这一行

throw new Exeption('There was a problem updating'); 

如果不是工作:

试试这个:

} catch(\Exception $e) { 

throw new \Exception('There was a problem updating'); 

从手动 Prefixing a name with \ will specify that the name is required from the global space even in the context of the namespace.

http://www.php.net/manual/en/language.namespaces.fallback.php

+0

不起作用.. :( – rZaaaa

+0

什么是在您的文件的顶部?任何命名空间或使用语句? – chanchal118

+0

@rZaaaa编辑我的答案。 – chanchal118