Welcome Guest, Not a member yet? Register   Sign In
Cannot access method in Controller!?
#1

(This post was last modified: 09-01-2020, 12:45 PM by blaasvaer.)

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.
Reply
#2

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!?
Reply
#3

In the $pathsPath, change FCPATH to ROOTPATH
Reply
#4

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.
Reply
#5

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

(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.
Reply
#7

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.
Reply
#8

You need to define all routes you want.
See https://codeigniter4.github.io/CodeIgnit...ting-rules
Reply




Theme © iAndrew 2016 - Forum software by © MyBB