Welcome Guest, Not a member yet? Register   Sign In
routing
#1

Hello,

This is a simple CI3 code that I am still new to:

Routing --> I already read the documentation and still having a little problem with it.  Can anyone help me?


routes.php


PHP Code:
$route['default_controller'] = 'welcome';
$route['add'] = 'welcome/table';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE

Welcome.php

PHP Code:
    public function index()
    {
        
$this->load->view('welcome_message');
    }
    
    public function 
table()
    {
        
$this->load->view('table');        
    } 

views/table.php


PHP Code:
<html>
<
title>Table</title>
<
body>

<
p>This is for table</p>

</
body>

</
html

I am trying to test the codes by typing this url:  http://localhost/ci3/add


Code:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the [[email protected]ocalhost]webmaster[/email].
Error 404
[url=http://localhost/]localhost[/url]
Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2


I wonder why?
" If I looks more intelligence please increase my reputation."
Reply
#2

If you're not us get mod_rewrite to remove index.php from your URLs, then try /index.php/add.
Reply
#3

(This post was last modified: 02-22-2016, 11:21 PM by freddy.)

as like @skunkbad  said you need to call it by href you cannot type in url,

let me teach you ya

here is router.php
Code:
$route['default_controller'] = 'welcome';
$route['add'] = 'welcome/table';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

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

class Welcome extends CI_Controller {


public function index()
   {
       $this->load->view('welcome_message');
   }
   public function table()
   {
       $this->load->view('table');        
   }
}

view calling from welcome
Code:
<h1> Here is view from welcome </h1>
<a href="<?php echo site_url('add') ?>">Click here to see router</a>

view calling by function table
Code:
<h1> Here is view from table function </h1>
Reply
#4

(This post was last modified: 02-23-2016, 02:34 AM by davy_yg.)

Hey, I wonder did I configure the router correctly?

I wonder why I have type this to open the table:

http://127.0.0.1/ci3/index.php/welcome/table ?

I also try altering my .htaccess in order to remove index.php from the url and have not been successful yet.  Can you help?

.htaccess

Code:
<IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /

       # Removes index.php from ExpressionEngine URLs
       RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
       RewriteCond %{REQUEST_URI} !/system/.* [NC]
       RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

       # Directs all EE web requests through the site index file
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Can you help me figure why I cannot remove the index.php?

Thanks in advance.
" If I looks more intelligence please increase my reputation."
Reply
#5

(02-23-2016, 02:13 AM)davy_yg Wrote: Hey, I wonder did I configure the router correctly?

I wonder why I have type this to open the table:

http://127.0.0.1/ci3/index.php/welcome/table ?

I also try altering my .htaccess in order to remove index.php from the url and have not been successful yet.  Can you help?

.htaccess

Code:
<IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /

       # Removes index.php from ExpressionEngine URLs
       RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
       RewriteCond %{REQUEST_URI} !/system/.* [NC]
       RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

       # Directs all EE web requests through the site index file
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Can you help me figure why I cannot remove the index.php?

Thanks in advance.

well first issue already solved or not ?
Reply
#6

(This post was last modified: 02-23-2016, 02:56 AM by freddy.)

this is how to remove index.php

ht acsess
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

then goes to config.php find
Code:
$config['index_page'] = 'index.php';

change become
Code:
$config['index_page'] = '';

then you success remove index.php this i give source code, just learn on it in here
Reply
#7

Hello,

I have followed your last advice and still have not been successful removing the index.php

I still have to type: http://127.0.0.1/ci3/index.php/welcome/table

to show the table.

I have alter .htaccess :

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]


config.php

$config['index_page'] = '';
" If I looks more intelligence please increase my reputation."
Reply
#8

(02-23-2016, 10:50 AM)davy_yg Wrote: Hello,

I have followed your last advice and still have not been successful removing the index.php

I still have to type:  http://127.0.0.1/ci3/index.php/welcome/table

to show the table.

I have alter .htaccess :

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]


config.php

$config['index_page'] = '';

Where is your RewriteBase /    ?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(02-23-2016, 10:50 AM)davy_yg Wrote: Hello,

I have followed your last advice and still have not been successful removing the index.php

I still have to type:  http://127.0.0.1/ci3/index.php/welcome/table

to show the table.

I have alter .htaccess :

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]


config.php

$config['index_page'] = '';

duh, good luck yah
Reply
#10

For what it's worth, my standard .htaccess:


Code:
RewriteEngine On
RewriteBase /

RewriteRule ^(system|application|cgi-bin) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB