Hi I’m learning PHP using the book “PHP & MYSQL: Notice to Ninja” version 7 completely on my own- no bootcamp or or college courses. I was formerly a C language/Unix programmer a long time ago.
I have been following the book nicely but I’m now completely stuck with URL rewriting part. I’m getting the error : Fatal error: Uncaught Error:
Call to undefined method JokeController::public() in C:\Users\glori\Documents\www\entrypoint\classes\EntryPoint.php:21
Stack trace: #0 C:\Users\glori\Documents\www\entrypoint\public\index.php(9): EntryPoint->run('entrypoint/publ...') #1 {main}
thrown in C:\Users\glori\Documents\www\entrypoint\classes\EntryPoint.php on line 21.`
Why is there an undefined method? I downloaded this code directly from Github.
Is there anyone who can help me? I’m new to this and I don’t have a bootcamp or a teacher. Just this book and a couple of youtube videos. Thanks in advance, Gloria
Can you post your EntryPoint.php file? From what I see of the examples in that book, there is no public() method on the JokeController. Taking a look at line 21 of the EntryPoint.php file will tell us more about what you are calling and how you are calling it.
Edit: I think if I understand what might be happening, you are passing an “action” parameter which is suppose to resolve to a method name on JokeController. So if “action” is “home” then it would call the home method on JokeController. If you are trying to call action with a value of “public” then make sure there is a public method on JokeController. But that is just guessing at this point.
Specifically, EntryPoint->run isnt looking for a filepath.
It expects to receive a route in the form “controllername/action[/param1[/param2…]]”;
Take input. Split on /.
the first word (array index 0) defines what controller should be performing the action;
the second word (array index 1) defines what action (method) that controller should take;
any additional words are passed as parameters to the action.
Thanks. I don’t understand what is going wrong as I am using the code directly from github. What should the URL look like? What should the .htaccess look like if I’m using Apache?
My current .htaccess file is in my public folder and it looks like this:
RewriteEngine on
RewriteCond % {REQUEST_FILENAME} !-f
RewriteCond % {REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [NC,L,QSA]
I can not run the script with this file in place at all. when I put it in the public folder or in my main folder, htdocs.