Welcome Guest, Not a member yet? Register   Sign In
Error 404 Object not found
#1

Hello, I work almost one week on this problem and can´t think any furhter myself. 
I´m new at codeigniter and in php programming as well. 

I try to explain you my problem, but if you need more information please ask. 

My routes: 

PHP Code:
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE


In my controller' directory I have the file: login.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Login extends CI_Controller {
 
   
    public 
function index () {
 
       
        $this
->load->view('first_message');
 
      


The index function here loads the view: first_message.php

Code:
<html>
   <head>
      <title> Welcome to Rosa </title>
   </head>
   
   <body>        
       <h2>Welcome to Rosa </h2>
       
      <?php           
       $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
       $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
       
       if (isset($username, $password)) {    
     
          if (!$username){
              //no username
           echo "Please enter a username.";
          }      
         if (!$password){
             //no Password
          echo "Please enter a password.";
         }      
       }
      else {
          //Button isn´t set
      }
      ?>

       <form action='page1.php' method='post'>            
           Username: <input type="text" name="username"><br />
           Password: <input type="text" name="password"><br />            
           <input type='submit' value='Login'>
       </form>
   </body>
   
</html>

So far, everything works fine. The URL in my browser is now: localhost/home
After typing the username and the password I push the "Login"-Button. 

Now the browser links to this URL: http://localhost/home/page1.php to start page1.php:

PHP Code:
<?php
include_once 'application/views/second_message.php';
defined('BASEPATH') OR exit('No direct script access allowed');


class 
Page1 extends CI_Controller {
 
   
    
    public 
function index () {
 
       
        $this
->load->view('second_message');
 
   }
 
   


Instead, I get the error: 

Object not found! The requested URL was not found on this server.

So, I hope it became clear what my problem is and I hope you can give me hint to solve it. 

Thank you and best regards
Reply
#2

Your page1 is it's own controller meaning the URL localhost/home/page1 will not work because page1 is not a method of the home controller.

Change the url to localhost/page1 or add the page1 method to your home controller.
Reply
#3

It seems you don't understand the relation between URL and controller (file and name) in CodeIgniter.
See http://www.codeigniter.com/user_guide/general/urls.html
And it would be better you read http://www.codeigniter.com/user_guide/tu...index.html
Reply
#4

Thank you for the hints.

Now I understand the constructs of an URL:
http://example.com/[controller-class]/[controller-method]/[arguments]

So, I know my page1.php should be a method of the controller-class login.php.

But I still don´t know how it helps me to open the view second_message.php if I click on the login-button.

So when I change to a method in the controller-class, what do I write in: .....action= ''.....   Huh
Reply
#5

(This post was last modified: 11-14-2015, 12:04 PM by Martin7483.)

If page1 is a method of your Controller Login then your URL would be
http://www.example.com/login/page1

And an action of a form points to a page...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB