CodeIgniter Forums
Cannot access method in Controller!? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Cannot access method in Controller!? (/showthread.php?tid=77434)



Cannot access method in Controller!? - blaasvaer - 09-01-2020

I've set this in my App\Config\App.php: public $baseURL = 'http://localhost/my_project/';

I've added this in my Home Controller:

Code:
<?php namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view('welcome_message');
    }

    public function test ()
    {
        return view('test');
    }
}

I've copied the index.php and .htaccess from the public directory into the root and modified the path accordingly:

Code:
$pathsPath = realpath(FCPATH . 'app/Config/Paths.php'); // removed the preceding dots ../

I've also added the view test.php in the Views directory ...

Now, why can't I access the test method in the Home controller by doing this:

Code:
http://localhost/my_project/test

?

Well. Maybe because I didn't add the Controller name before the method OR didn't set it specifically in the Routes.php ...

I just 'thought' that, as the default controller is set, it would 'automagically' use that if left out ... but that would probably have been a bit weird ... so.


RE: Cannot access method in Controller!? - blaasvaer - 09-01-2020

OK, so I received an e-mail that someone had replied to my post:

Code:
blaasvaer,

jreklund has just replied to a thread which you have subscribed to at CodeIgniter Forums. This thread is titled Cannot access method in Controller!?.

Here is an excerpt of the message:
------------------------------------------
This one should work, you haven't done any routing to remove home from your url. So read up on that &hellip; (visit the thread to read more&hellip;)
------------------------------------------

To view the thread, you can go to the following URL:
https://forum.codeigniter.com/thread-77434-newpost.html

There may also be other replies to this thread but you will not receive anymore notifications until you visit the board again.

Thank you,
CodeIgniter Forums Staff

------------------------------------------
Unsubscription Information:

If you would not like to receive any more notifications of replies to this thread, visit the following URL in your browser:
https://forum.codeigniter.com/usercp.php?action=removesubscription&tid=77434&my_post_key=824542f3456ed0cd7a1b51d2dac79100

But I don't see the reply in the thread!?


RE: Cannot access method in Controller!? - paulbalandan - 09-01-2020

In the $pathsPath, change FCPATH to ROOTPATH


RE: Cannot access method in Controller!? - blaasvaer - 09-01-2020

To prevent other answers I'll throw my own quick replies as a 'regular' reply.

Well. Maybe because I didn't add the Controller name before the method OR didn't set it specifically in the Routes.php ...

I just 'thought' that, as the default controller is set, it would 'automagically' use that if left out ... but that would probably have been a bit weird ... so.


RE: Cannot access method in Controller!? - jreklund - 09-02-2020

That's why I deleted my reply, as I noticed you had already found out why. xD


RE: Cannot access method in Controller!? - blaasvaer - 09-02-2020

(09-02-2020, 12:42 AM)jreklund Wrote: That's why I deleted my reply, as I noticed you had already found out why. xD

Well, I ‘guess’ the system failed to notify me about the deletion then ... which I think would be the proper respond from a system like this ... but maybe that’s just me.

Thanks anyway.


RE: Cannot access method in Controller!? - look - 12-04-2022

Why the learn/test curve in ci4 is so high?....
simple things, just starting - and already i'm in forums QA.

out of the box - Index method works in default controller.
why not other methods?
how to call other methods?
any call result with :
Cannot access the default controller "Home" with the controller name URI path.

can't be that there is no simple answer to it.


RE: Cannot access method in Controller!? - kenjis - 12-05-2022

You need to define all routes you want.
See https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#setting-routing-rules