(07-02-2016, 07:24 AM)fromberg Wrote: (07-02-2016, 02:06 AM)arma7x Wrote: (07-01-2016, 10:07 PM)fromberg Wrote: Hi All,
thanks for your feedback and suggestions.
I have tried all but still the same problem. I downloaded the latest CI 4 from repository.
My environment is Windows.
I will keep trying. If any additional tip, would be highly appreciated.
Thanks and regards,
This is controller file inside sub-folder Ajax in Controller folder;
PHP Code:
<?php namespace App\Controllers\Ajax;
class Test extends \CodeIgniter\Controller
{
public function index()
{
echo 'hi Im test in ajax sub folder';
}
//--------------------------------------------------------------------
}
Edit your route file, /application/Config/Routes.php by adding:
PHP Code:
$routes->add('ajax/test', 'Test::index', ['namespace' => 'App\Controllers\Ajax']);
It's works for me. Using CI4, if you namespace the controller, you have to set $routes->setDefaultNamespace('App\Controllers'); and define $routes->add() for each controller(Having 404NotFound problem if I’m did not do this).
Hi arma7x,
I highly appreciate your help, it works now.
Just curious, should this be done like this? Shouldn't it be working automatically?
Thanks and regards,
Read
explanation here from kilishan.
But only controller with namespace(if I'm not wrong) you need to define route;
PHP Code:
$routes->add('ajax/test', 'Test::index', ['namespace' => 'App\Controllers\Ajax']);
For controller under subfolder without using namespace, I didn’t find any information in documentation. So, by using namespace able to solve this problem.
Keep calm.