1

i`m using codeigniter 4 and try to use a controller from other controller

i have 2 controllers in Controllers folder, Home.php dan Shop.php

Home.php

<?php

namespace App\Controllers;

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


function validation()
    {
        $shop = new Shop();
        echo $shop->product('laptop', 'brand');

    }


}

and Shop.php

<?php

namespace App\Controllers;

class Shop extends BaseController
{

    public function index()
    {
        return view('shop');
    }
   

    public function product($type, $product_id)
    {
        echo "this is a $type and $product_id";
    }


}

when i try to load localhost:8080/home/validation

the result still : Whoops! We seem to have hit a snag. Please try again later...

how to do the right way ? thank you

  • Does this answer your question? [How to load a controller from another controller in codeigniter?](https://stackoverflow.com/questions/14165895/how-to-load-a-controller-from-another-controller-in-codeigniter) – steven7mwesigwa Mar 07 '21 at 01:27
  • not yet, its litte bit different with codeigniter 4. i also try load with require_once. still dont work – Dendy B. Sulistyo Mar 07 '21 at 09:26
  • 1
    I tested your code locally and it seems to work just fine. `this is a laptop and brand`. Nonetheless, navigate to your logs to see the **error logs.** 1. In your project directory, navigate to `writable\logs\log-2021-03-07.log` 2. clear the contents of that file. 3. open your browser and reload `localhost:8080/home/validation` again. 4. Then edit your SO question pasting the contents of the previously cleared **error log file** `log-xxxx-xx-xx.log` – steven7mwesigwa Mar 07 '21 at 10:06
  • 1
    You could as well make your life easier by simply [turning on error reporting in Codeigniter 4 instead of inspecting the error log files](https://stackoverflow.com/a/60564586/7376590) – steven7mwesigwa Mar 07 '21 at 10:26
  • 1
    it is solved. thank you i change my installation with composer. it is runs good before, i only extract the ci4 source, install intl extension and create .env how to accept your answer @steven7mwesigwa ? – Dendy B. Sulistyo Mar 07 '21 at 16:34
  • I didn't post an answer since your source code was correct and working already when tested on my local machine. Since you have posted an answer, you can [mark your own answer as accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – steven7mwesigwa Mar 08 '21 at 13:10

1 Answers1

0

it is solved. i change my installation with composer. it is runs good now. before, i only extract the ci4 source, install intl extension and create .env