CodeIgniter Forums
routing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: routing (/showthread.php?tid=64468)

Pages: 1 2


routing - davy_yg - 02-22-2016

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=postmaster@localhost]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?


RE: routing - skunkbad - 02-22-2016

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


RE: routing - freddy - 02-22-2016

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>



RE: routing - davy_yg - 02-23-2016

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.


RE: routing - freddy - 02-23-2016

(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 ?


RE: routing - freddy - 02-23-2016

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


RE: routing - davy_yg - 02-23-2016

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'] = '';


RE: routing - InsiteFX - 02-23-2016

(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 /    ?


RE: routing - freddy - 02-23-2016

(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


RE: routing - skunkbad - 02-23-2016

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]