Jump to content

Fatal error: Class 'services' not found


mrooks1984

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.