0

I have some problem with routing and parameters.

I have routing in routes.php like this :

$route['register/(:any)'] = 'member/register/$1';

And in my controller I have like this :

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

class Register extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Page_model');
        $this->load->model('member_model');
        $this->load->model('login_model');

        $this->load->library('session');
        $this->load->helper('url');
        $this->load->helper('html');
        $this->load->helper('form');

    }

    public function index()
    {
        $slug = $this->uri->segment(1);
        $type = $this->uri->segment(2);

        var_dump($type);
        exit();

        if ($slug != NULL) 
        {
            $data['page'] = $this->Page_model->get_page($slug);

            if (empty($data['page'])) 
            {
                // show_404();
                $data['page'] = new stdClass();
                $data['page']->page_template = 'forofor';
                $data['page']->title = 'Page Not Found';
                $data['page']->meta_description = 'Page Not Found';
                $data['page']->meta_keywords = 'Page Not Found';
            }
            else
            {
                $data['slider'] = $this->Page_model->get_slider($data['page']->page_id);
            }
        }
        else
        {
            $data['page'] = $this->Page_model->get_page('home');
            $data['slider'] = $this->Page_model->get_slider($data['page']->page_id);
        }

        $data['head_title'] = $data['page']->title;

        // load all settings and data
        $data['settings'] = $this->Page_model->get_settings();
        $data['gallery'] = $this->Page_model->get_gallery();

        $data['meta'] = 
            array(
                array(
                    'name' => 'description', 
                    'content' => $data['page']->meta_description
                ),
                array(
                    'name' => 'keywords',
                    'content' => $data['page']->meta_keywords
                )
            );

        // $data['meta'] = $this->meta;

        $data['menu'] = $this->Page_model->get_menu('frontend','header');
        $data['settings'] = $this->Page_model->get_settings();
        $data['notice'] = $this->session->flashdata('notice');

        // $this->load->view('frontend/template/index_full', $data);

        $this->load->view('frontend/template/head', $data);
        $this->load->view('frontend/template/pre_header');
        $this->load->view('frontend/template/header');
        $this->load->view('frontend/template/modal');
        //$this->load->view('frontend/template/modal_registration');
        /*if ($page[0]->page_template != 'forofor' && $data['page']->slider != 0) 
        {
            $this->load->view('frontend/template/slider');
        }*/
        if ($slug != 'home' && $slug != NULL) 
        {
            //$this->load->view('member/'.$data['page']->page_template);
            $this->load->view('member/register');
        }
        else
        {
            $this->load->view('frontend/template/slider');
            $this->load->view('frontend/page_template/homepage');
        }
        $this->load->view('frontend/template/pre_footer');
        $this->load->view('frontend/template/footer');
        $this->load->view('frontend/template/js');
        $this->load->view('frontend/template/closing_body_html');
    }
}

But if I input the routes in my browser it gives me 404 Page not found

This is my routes :

127.0.0.1/project/register/buyer

And 127.0.0.1/project/ is my Base URL

Anyone knows why it could be happen ?

Thank you.

1
  • You have posted your Register controller and calling Member controllers Register function in your routes which is wrong,so please let us know what exactly you require Commented Sep 22, 2016 at 9:02

2 Answers 2

5

Your routing is wrong. According to your post you are setting Member controller then register method.

Try below code

$route['register/(:any)'] = 'register/index/$1';
$route['register/(:any)/(:any)'] = 'register/index/$1/$2'; // Optional

The second option is only optional:

Sign up to request clarification or add additional context in comments.

Comments

3

This is how routes work in Codeigniter

Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:

example.com/class/function/id/ In some instances, however, you may want to remap this relationship so that a different class/method can be called instead of the one corresponding to the URL.

For example, let’s say you want your URLs to have this prototype:

example.com/product/1/ example.com/product/2/ example.com/product/3/ example.com/product/4/ Normally the second segment of the URL is reserved for the method name, but in the example above it instead has a product ID. To overcome this, CodeIgniter allows you to remap the URI handler.

Reference : https://www.codeigniter.com/userguide3/general/routing.html

So,the routes follow this syntax

$route['route_url'] = 'controller/method/$paramater';

So,your route will be

Let me know your queries

$route['register/(:any)'] = 'register/index/$1';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.