mrooks1984 Posted October 13, 2011 Share Posted October 13, 2011 hello, i am hoping someone can help, been working on my own mvc with help from tutorials, but i am stuck with this error: Fatal error: Class 'services' not found in C:\xampp\htdocs\Workspace\Cyberglide\libs\Bootstrap.php on line 27 were it says services that changes when i type a different item in the url, loads the error page but says that at the bottom of the page. hoping someone can help me where i gone wrong: <?php class Bootstrap { function __construct() { $url = isset($_GET['url']) ? $_GET['url'] : null; $url = rtrim($url, '/'); $url = explode('/', $url); //print_r($url); if (empty($url[0])) { require 'controllers/index.php'; $controller = new Index(); $controller->index(); return false; } $file = 'controllers/' . $url[0] . '.php'; if (file_exists($file)) { require $file; } else { $this->error(); } $controller = new $url[0]; $controller->loadModel($url[0]); // calling methods if (isset($url[2])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}($url[2]); } else { $this->error(); } } else { if (isset($url[1])) { if (method_exists($controller, $url[1])) { $controller->{$url[1]}(); } else { $this->error(); } } else { $controller->index(); } } } function error() { require 'controllers/error.php'; $controller = new Error(); $controller->index(); return false; } hope someone can help, many thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/ Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 Obviously this line $controller = new $url[0]; is not resolving to a class that php can find. Do you have a class called services? and is it included within this script? Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278928 Share on other sites More sharing options...
mrooks1984 Posted October 13, 2011 Author Share Posted October 13, 2011 hi, no i dont have one called services, thats the point. i want to get the error page working correctly for when a wrong url is typed. i know what the error is say i just dont have enough knowledge of php at the meoment to fix it. so i came here hoping someone could help. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278935 Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 $file = 'controllers/' . $url[0] . '.php'; if (file_exists($file)) { require $file; $controller = new $url[0]; $controller->loadModel($url[0]); } else { $this->error(); } Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278937 Share on other sites More sharing options...
mrooks1984 Posted October 13, 2011 Author Share Posted October 13, 2011 thanks for your help, i am now getting this message: from what i could see from the code you told me i moved it into the file function like so: $file = 'controllers/' . $url[0] . '.php'; if (file_exists($file)) { require $file; $controller = new $url[0]; $controller->loadModel($url[0]); } else { $this->error(); } but now i get this error : Notice: Undefined variable: controller in C:\xampp\htdocs\Workspace\Cyberglide\libs\Bootstrap.php on line 42 Fatal error: Call to a member function index() on a non-object in C:\xampp\htdocs\Workspace\Cyberglide\libs\Bootstrap.php on line 42 only get it on the error ones, please help. Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278942 Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 To be honest, as far as mvc implementations go, there are quite a few floors in your approach. Your current error can likely be fixed by ensuring that your error() method kills any further execution using die. Unfortunately however, I'm not sure this will be your only issue. Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278943 Share on other sites More sharing options...
mrooks1984 Posted October 13, 2011 Author Share Posted October 13, 2011 thanks for your advice, the die at the end solved it. if you have time could you please tell me what the flaws from this system is and give me any advice? or if there is a simple opensource alternative to work from. this is the first time i have used this sort of system so my knowledge is very limited. i used to just use code without functions and class. but was told to use a mvc as its a better way of doing things. thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278949 Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 There is nothing in particular that stands out too much, it's just not very flexible. You have paths hardcoded into your class, you have no way of passing further parameters along with your requests and I'm also not sure this syntax will even work. $controller = new $url[0]; Quote Link to comment https://forums.phpfreaks.com/topic/249022-fatal-error-class-services-not-found/#findComment-1278953 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.