Question

I'm getting an unexpected exception. When I Update data like this:

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());
}

It returns this error: 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

But the strange thing is I have no Exeption.php class? Also, the line 32 refers to my autoload:

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

My update method in Restaurant class is like this...

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

ANd the update method from DB class is PDO prepare, execute, fetch

Any guidance?

Was it helpful?

Solution 2

It was a typo in the class method

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

Also... the exception whas thrown because there was a error in de DB method I was selecting WHERE id = $ID

but in MySQL it was not called id but rest_id.

OTHER TIPS

You have spelling mistake Exeption will be Exception in this line

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

If not that works:

Try this:

} catch(\Exception $e) {

and

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

From manual 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top