Welcome Guest, Not a member yet? Register   Sign In
404 - can't find controller
#1

[eluser]karstyn[/eluser]
I have a login page that after submit checks a database for authentication, and if successful uses the Location redirect to load another controller page. I'm getting a 404 Not Found error when trying to load the next page (portal).

Here is login page (welcome) controller code:

<?php

class Welcome extends Controller {

function Welcome()
{
parent::Controller();
}

function index()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['teacherId'])) {
$this->cifx->SetDBData('NN_PETS.fp7', 'FX_people');
$this->cifx->AddDBParam('ID_employeeNum_c', $_POST['teacherId'], 'eq');
$results = $this->cifx->FMFind();

$auth = false;
foreach ($results['data'] as $result) {
if ($result['web_login_pwd'][0] == $_POST['password']) {
$auth = true;
}
}

if (!$auth) {
$viewData['msg'] = "The username and/or password you entered is invalid.";
$viewData['msgClass'] = "error";
} else {
$_SESSION['loggedIn'] = true;
$_SESSION['teacherId'] = $_POST['teacherId'];
header("Location: " . base_url() . 'portal');
exit();
}
}
$this->load->view('welcome', $viewData);
}

function logOut()
{
$this->auth->logOut($this->uri->segment(3));
}
}
?>

and here is the start of the portal controller page:

<?php

class Portal extends Controller {
function Portal()
{
parent::Controller();

}

function index()
{

$user = $this->auth->loggedIn();

if (isset($_POST['role'])) {

$this->cifx->SetDBData('NN_PETS.fp7', 'FX_role');
$this->cifx->AddDBParam('__K_ROLE_ID', $_POST['role'], 'eq');
$roleResults = $this->cifx->FMFind();

foreach ($roleResults['data'] as $k => $role) {
$_SESSION['role'] = $role;
$_SESSION['roleKey'] = $k;
break;
}
.....
(don't be concerned with the 'cifx', that works in this case)

Why can't it load the portal page? base_url() is evaluating to 'http://127.0.0.1:8080/portal' - which seems right to me.

Odd thing is that this code works on another server - so I must be missing a config somewhere?

For configs I have edited both the config/database.php and the config/config.php files to point to my local setup. Anywhere else I may need to look for changes to make?

--Karstyn
#2

[eluser]TheFuzzy0ne[/eluser]
A few observations. You'll be better of using CodeIgniter's session library, it will make your code easier to follow. Also, load the URL helper, and use redirect(). This may solve your problem. Also, please use code tags, so we can follow you code a bit better. Smile

What's the URI string in your address bar after the redirect has taken place?
#3

[eluser]karstyn[/eluser]
The URI looks correct to me - http://127.0.0.1:8080/portal

I'm new to fairly new to PHP in general and very new to CI in particular. I've taken over this site from another developer and am just trying to get it working locally so I can test changes before uploading to the live site. I thought that would be the simple part! So far it's not been easy at all!

I'll checkout the URL helper and see if that makes a difference.

Thanks
#4

[eluser]TheFuzzy0ne[/eluser]
Check your htaccess file to ensure you can actually call URLs like that. You might find that http://localhost:8080/index.php/portal may work better (I substituted your IP address with localhost as it's easier to type).
#5

[eluser]karstyn[/eluser]
Excellent!!

Changing base_url to site_url is working, and then I have to add a slash to what follows in the code.

However I'm not sure I'm following how site_url is getting created. Looking in url_helper.php seems to be where that is declared. It is then looking at config.php for site_url, but I only have base_url in config.php - what am I missing?

Thanks for all the help!
#6

[eluser]TheFuzzy0ne[/eluser]
Actually it's just an alias for a method called "site_url" which is declared in ./system/libraries/Config.php:
Code:
function site_url($uri = '')
        {
                if (is_array($uri))
                {
                        $uri = implode('/', $uri);
                }

                if ($uri == '')
                {
                        return $this->slash_item('base_url').$this->item('index_page');
                }
                else
                {
                        $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
                        return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
                }
        }
#7

[eluser]karstyn[/eluser]
Ahh, that makes a lot more sense!

Thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB