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

[eluser]amii[/eluser]
This is my first post so I would like to say hello to everyone. I try to transfer my application to the code igniter framework and the obstacles are URL's. Basically in the old-style application the URL system was sth like this:

index.php
Code:
if(!isset($_GET['p']) || !file_exists('view/'.$_GET['p'].'.php')) {$_GET['p']="main";}

include_once('header.php');  
include_once('view/'.$_GET['p'].'.php');  //dynamically main content section loader
include_once('footer.php');

Therefore URL's in the old-fashioned style look similar like this: www.example.com/index.php?p=register and afterwards view/register.php has been put in the main content section - that seems to be very simple. This was good due to fact that header.php and footer.php were included only once. However in the code igniter this issue is not so simple at all.

I dont have idea how to make this thing works in the same way like in the old-fashioned application, any ideas guys ?
#2

[eluser]Jaketoolson[/eluser]
You'll need to create controllers.

http://www.example.com/users/register

would load your users.php controller in the /applications/controllers/ folder and /register/ would be a function called register within the users.php controller class.

http://ellislab.com/codeigniter/user-gui...llers.html
#3

[eluser]amii[/eluser]
Thanks for the answer Smile
Though, I have controller it's called welcome.php it looks like below:
However if i try to access:
http://127.0.0.1/piotr/seoprecel/index.p...ome/precel //works 100 %
http://127.0.0.1/piotr/seoprecel/ //works 100 %
http://127.0.0.1/piotr/seoprecel/index.p...ome/precel //no styles, images and js visible
http://127.0.0.1/piotr/seoprecel/welcome/precel //got no found error
I have a local server apache2 on ubuntu


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

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://ellislab.com/codeigniter/user-guide/general/urls.html
     */

        
    public function index()
    {  
              
                define('SITE',site());   //adres skryptu
                $this->load->view('header');  //naglowek strony
                $this->load->view('main');
                $this->load->view('footer');

    }

        public function precel()
        {

                define('SITE',site());   //adres skryptu
                $this->load->view('header');  //naglowek strony
                $this->load->view('precel');
                $this->load->view('footer');

        }

        public function mixer()
        {

                define('SITE',site());   //adres skryptu
                $this->load->view('header');  //naglowek strony
                $this->load->view('mixer');
                $this->load->view('footer');

        }
      

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

.htaccess
Code:
DirectoryIndex index.php
RewriteEngine on
AddType application/x-shockwave-flash .swf
RewriteCond $1 !^(index\.php|images|css|js|swf|flash|mainvideo|robots\.txt|favicon\.ico|license.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

The question is how to make links look like this:
http://127.0.0.1/piotr/seoprecel/precel
insted of this
http://127.0.0.1/piotr/seoprecel/index.p...ome/precel

The second question (less important). Is there any technique to include header and footer only once. In my controller they are loaded each time for each site (that's bad for site benchmarking).
#4

[eluser]Jaketoolson[/eluser]
To remove 'index.php' from your url's, you need to make changes to your config.php file.

Code:
//set this to empty
$config['index_page'] = '';

//i use query string
$config['uri_protocol']    = 'QUERY_STRING';

htaccess:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
#5

[eluser]amii[/eluser]
Unfortunately it doesnt work. You can see the application here seoprecel.net (not all links are marked correct)
Only types of links below work correct:
http://seoprecel.net/?/welcome/precel
http://seoprecel.net/index.php?/welcome/precel
#6

[eluser]toopay[/eluser]
Code:
$config['uri_protocol']    = 'AUTO';
or
Code:
$config['uri_protocol']    = 'PATH_INFO';




Theme © iAndrew 2016 - Forum software by © MyBB