Welcome Guest, Not a member yet? Register   Sign In
Keep displaying "404 Page Not found" except default welcome message
#1

Hi All,

Just installed Codeigniter 4 in Windows Server, but I've found that all custom pages displayed with a message "404 Page Not found" except the default welcome page could be viewed normally. I did not have any setting change yet. Please advise what's wrong with it. Thanks

Joanne

Attached Files Thumbnail(s)
   
Reply
#2

(This post was last modified: 07-07-2020, 09:31 AM by captain-sensible.)

ok well , keeping it simple urls in web browser are linked to routes , which are linked to controllers.

So as default with no change to settings in app/Config/Routes.php there is :

$routes->get('/', 'Home::index');


that basically means a url in address bar of web browser with say something like 127.0.0.1 (localhost) will use that route .


in app/Controllers/Home.php we have :

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

So looking back at '/' which for all purposes equates to 127.0.0.1 on apache local host


tells system use Class Home.php in Controllers and class method index()

index loads welcome_message which you will find at app/Views and is called welcome_message.php



now lets look at say a route i defined at one point :

$routes->get('test','Portfolio::test');

that route would be invoked by a url such as :

127.0.0.1/test

it would look for Class Portfolio and its one of its methods called test


lets have look inside part of the test method:


$data = [
'title' => 'portfolio',
'info'=>'currently portfolio is empty',
'date'=>$date
];

echo view('header', $data);
echo view('info', $data);
echo view('footer',$data);

}

so its going to load /app/Views/header.php
/app/Views/info.php
/app/Views/footer.php

in that order. header is used bu all pages and holds link to css file and title stuff
info.php is the middle section
footer.php is at the bottom and holds social media links etc.

now notice 'info'=>'currently portfolio is empty',

that gets passed to info.php and inside info.php I have a line


<?php echo $info; ?>
//which outputs on the web page : currently portfolio is empty

So basically the set up is of course MVC
models do database controllers do basic logic and load views.if you don't tell the system that views should be loaded and which ones they won't be



i guess your starting point is here : https://codeigniter4.github.io/CodeIgnit...index.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB