0

Hello im working with code igniter and I try to send parameters from url into view to controller

My Controller

public function mainView($num=null) {
        $this->load->view('header');



        // $data = array('foo[' => 'Hello', 'bar' => 'world');
        if (!isset($_SESSION[$this::jsondevices])) {
            var_dump("Descargo");

            $_SESSION[$this::jsondevices] = $this->restlib->consumirDominiosDeMoca($this->restmodel->modelUserDevices());
            $_SESSION[$this::jsontags] = $this->restlib->consumirDominiosDeMoca($this->restmodel->modelTagsMoca());
        }
        var_dump("No descargo");
        $data = $this->piemodel->mainValues($this, $_SESSION[$this::jsondevices], $_SESSION[$this::jsontags]);

        $this->load->view('user/login/vistachart', $data);
        $this->load->view('footer');
    }

My js

  window.location.href = "<?= base_url('home2/$1')?>";

And my route

$route['home2/(:num)'] = 'user/mainView/$1';

And the result

404 Page Not Found

But I try with $route['home'] = 'user/mainView'; Work's What Im doing wrong?

1 Answer 1

1

Send your parameter like this in js:

 window.location.href = "<?= base_url('home2/1')?>";

it redirects to user/mainView/1 where 1 is parameter.

Also don't forget to load url helper in application/config/autoload.php.

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

4 Comments

glad to help you.best of luck.
the url charge but param is null , ever
try using public function mainView($num=FALSE).
For more see here codeigniter.com/user_guide/tutorial/news_section.html hope you will get something new.

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.