2
Contributors
20
Replies
21
Views
4 Years
Discussion Span
Last Post by moroccanplaya
Featured Replies
  • 1

    The problem may be: [CODE] require 'controllers/' .$url; // this should open controllers/index.php $controller = new $url; // this should be Index (the class name) [/CODE] The following could help: [CODE] require 'controllers/' . strtolower($url) . '.php'; $controller = new $url; [/CODE] If you want to open [iCODE]index.php?url=Index[/iCODE] Read More

0

You have to provide ?url= in the address bar. If that is missing, you get the index error. You can change it to this:

$url = isset($_GET['url']) ? $_GET['url'] : '<no url set>';
echo $url;
0

hi thanks for the help, it has cleared the errors but its not echoing out the url ? ive been following a php tutorial and i dont how he has got it working

0

my index.php

<?php

$url = isset($_GET['url']) ? $_GET['url']: '<no url set>';
echo $url;


require 'controllers/' .$url . '.php';

$controller = new $url;





?>

my controller :

<?php
class Index {
    
    function __construct() {
        
        echo 'we are in index'; 
    }
}

?>

Edited by moroccanplaya: n/a

0

Warning: require(C:\wamp\www\mvc\controllers) [function.require]: failed to open stream: Permission denied in C:\wamp\www\mvc\index.php on line 7

0

What did you do? Pasting an error without showing your code is kinda useless.

Edited by pritaeas: n/a

0

( ! ) Notice: Undefined index: url in C:\wamp\www\mvc\index.php on line 3
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0

( ! ) Warning: require(C:\wamp\www\mvc\controllers) [function.require]: failed to open stream: Permission denied in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0

( ! ) Fatal error: require() [function.require]: Failed opening required 'controllers/' (include_path='.;C:\php\pear') in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0007 364448 {main}( ) ..\index.php:0

0

Show your code, not the call stack. Although the last error says the file does not exist, so you need to check that before you include it.

Edited by pritaeas: n/a

0

its the same code i showed you at the start here is :

index.php

<?php

$url = $_GET["url"];
echo $url;


require 'controllers/' .$url;

$controller = new $url;



?>

index.php in the folder called controller:

<?php
class Index {
    
    function __construct() {
        
        echo 'we are in index'; 
    }
}

?>

that is all i have

0

If there is no url specified, the require will fail, that is why you have those messages. You will have to call it as I specified earlier, or add error checking.

Edited by pritaeas: n/a

0

heres my .htaccess file


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?

0

http://localhost:8080/mvc/index.php?url=Index

it echos out index

and these error messages


( ! ) Warning: require(controllers/Index) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0005 365256 {main}( ) ..\index.php:0

( ! ) Fatal error: require() [function.require]: Failed opening required 'controllers/Index' (include_path='.;C:\php\pear') in C:\wamp\www\mvc\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0005 365256 {main}( ) ..\index.php:0

1

The problem may be:

require 'controllers/' .$url; //  this should open controllers/index.php
$controller = new $url; // this should be Index (the class name)

The following could help:

require 'controllers/' . strtolower($url) . '.php';
$controller = new $url;

If you want to open index.php?url=Index

Edited by pritaeas: n/a

Comments
great help
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.