I've created one test.php
file in location applications\\views\\test\\test.php
with controller in application\\controller\\Test.php
& model in applications\\models\\Test_model.php
.
In my routes.php
file, I have added $route['test']='test/view'
.
Please note there are some files present already which are working quite fine, one of which is login.php
& it has value in routes.php
as $route['login']='login/view'
. Plus this file does have same model & controller files in likewise location.
When I try to access localhost\\test
, it gives me 404 error whereas for localhost\\login
works quite fine.
Can anybody help in routing? I'm new to codeigniter & I could not resolve this issue.
EDIT
htaccess works fine as localhost\\login
is loading properly along with other few files.
EDIT 2
Test_model.php
<?php
class Test_model extends CI_Model{
public function __construct()
{
$this->load->database();
}
}
?>
test.php
<div>Testing</div>
Test.php
<?php
class Test extends MY_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('test_model');
}
public function view()
{
$this->loadHeader();
$this->load->view('test/test');
$this->loadFooter();
}
}
?>
routes.php
$route['test'] = 'test/view';
EDIT 3
When I try to access localhost\\application\\controllers\\Test.php
, it gives me an error that says Class My_Controller
not found. However, when I attempt to do it with any other file let's login
with with the same location, it gives me the same error.
So I guess, it's able to find the controller because it's giving an error obviously but not able to load anything else.
Is there some sort of config file in which I have to mention every new page I create or something? There has to be something. This is pretty basic & I'm not able to get to the root of it.
EDIT 4
So this is what a problem is. When I copied my test view file to pages folder, it worked. Of course in controller I edited path of the file.
Now the real question is why didn't new folder named test under views work?
Create a .htaccess
file and paste this code below
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Finally, the culprit was this line in routes.php
file:
$route['(:any)'] = 'pages/view/$1';
I was adding other route below this so it was getting default behaviour. I put them above this line & it worked like a charm. I never thought this could be the issue.
Line number matters, now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.