In CodeIgniter how can i pass an array type argument to a controller from url

how to pass data from view to controller in codeigniter
how to pass array from view to controller in codeigniter
how to pass variable value from controller to view in codeigniter
how to get array value in codeigniter controller
how to pass id from view to controller in codeigniter
codeigniter get uri->segment in view
how to send data from view to controller in codeigniter using ajax
how to pass id in base_url in codeigniter
//let my controller be C and method be:
    function X($array){}
//And my url to call it is:
    localhost/mysite/C/X/array

Well i tried it but it returns 400-Bad Request response. Does anyone know how to do it? Quick response will help me a lot//Thanx


localhost/mysite/C/X/?array=1&&?array=2....

$array = $this->input->get('array');

or

localhost/mysite/C/X/1,2,3,4,5

$array = explode(',' $this->uri->segment(n));

// in app/config/config.php

$config['permitted_uri_chars'] = 'a-z 0-9~%.:,_-';

My variant for array in url (/tours/novogodniye-turi/visa=yes;duration=small;transport=4,7,6,2/)

if ( ! function_exists('filter_parse_segment'))
{
    function filter_parse_segment($segment, $merge_to_get = FALSE)
    {   
        if(empty($segment))
        {
            return FALSE;
        }

        $parameters = explode(";", (string)$segment);

        if(empty($parameters))
        {
            return FALSE;
        }

        $parameters_array = array();

        foreach($parameters as $parameter)
        {
            if(empty($parameter))
            {
                continue;
            }

            $parameter = explode("=", $parameter);

            if( ! isset($parameter[0], $parameter[1]) or empty($parameter[0]))
            {   
                continue;
            }

            if(strpos($parameter[1], ','))
            {
                $parameter[1] = explode(",", $parameter[1]);
            }

            $parameters_array[$parameter[0]] =  $parameter[1];      
        }

        if($merge_to_get === TRUE)
        {
            $_GET = array_merge($_GET, $parameters_array);
        }

        return $parameters_array;
    }
}

// --------------------------------------------------------------------

if ( ! function_exists('filter_collect_segment'))
{
    function filter_collect_segment($array, $suffix = '', $remove = array())
    {   
        if(empty($array) || ! is_array($array))
        {
            return '';
        }

        $segment_str = '';

        foreach ($array as $key => $value)
        {

            if(empty($key) || in_array($key, (array)$remove))
            {
                continue;
            }

            if( ! $segment_str == '')
            {
                $segment_str = $segment_str.';';
            }

            if( ! is_array($value))
            {
                $segment_str = $segment_str.$key.'='.$value;

                continue;
            }

            if(empty($value))
            {
                continue;
            }

            $parsed_value = '';

            foreach ($value as $item)
            {
                if( ! $parsed_value == '')
                {
                    $parsed_value = $parsed_value.',';
                }

                if(is_array($item) || empty($item))
                {
                    continue;
                }

                $parsed_value = $parsed_value.$item;
            }

            $segment_str = $segment_str.$key.'='.$parsed_value;
        }

        if($segment_str != '')
        {
            $segment_str = $segment_str.$suffix;
        }

        return $segment_str;
    }
}


// --------------------------------------------------------------------

if ( ! function_exists('filter_key'))
{
    function filter_key($filter_array, $key, $value = NULL)
    {   
        if( ! isset($filter_array[$key]))
        {
            return;
        }

        if($value == NULL)
        {
            return $filter_array[$key];
        }

        if( ! is_array($filter_array[$key]) && $filter_array[$key] == (string)$value)
        {
            return $value;
        }

        if(is_array($filter_array[$key]) && in_array($value, $filter_array[$key]))
        {
            return $value;
        }

        return FALSE;
    }
}

How can I pass array as parameter from view to controller when click , When you create the new instance, you can pass a full or partial URL in the Assuming that you're in a controller that extends CodeIgniter\Controller you can get it like: You must pass true as the first parameter, otherwise, it will return the string You can filter the query values returned by passing an options array to the� (12-31-2015, 03:06 AM) Martin7483 Wrote: You don't pass data from a view to a Controller. You pass data from a Controller to a View. You do pass input data from a form to a controller. Using Ajax I need to pass an array of data to the controller


If you want the solution in the pretty nice URL then you have to loop the array first and then concatenate the elements with some - dash or + plus signs like this;

$array = array(1,2,3,4);
$string = "";

foreach($array as $value){
   $string .= $value."-";
}

$string = rtrim($string, "-");

redirect(base_url()."get_products?param=".$string);

And on the next page just get the param and use explode() function with - dash sign to create the array again.

Working with URIs — CodeIgniter 4.0.4 documentation, Create a View; Load the View; Pass array from controller to view; Load Once you have created the controller, the URL for the view would be: is that the array or the object is passed as the second parameter of the view� A controller often comprises of several functions and often the module’s logic demands passing data between the various functions of the Controller. This is a common enough scenario in many Codeigniter projects.


try your url like this

 if value you have to pass is
 [1,2,3,2]
 then
 localhost/mysite/index.php/C/X/1,2,3,2

How to Pass Data From Controller to View in CodeIgniter, The data is also passed by URL which is good for limited and less sensitive In this tutorial, I show how you can pass data between view and controller. <td>< input type='submit' name='submit' value='Submit'></td> </tr> The $this->input-> post() method returns an Associative array of submitted values. Hi, I'm new to codeigniter, and I'm struggling with this: I have my view "vehicles" in which all the available vehicles cards are displayed. If I click on a card I'd like to be routed to a view of the requested vehicle showing all the details of the car.


In a simple way you can make the array a string with some special character in between the values of the array.

Then in the landing page you can split the string with the special character and get the array again.

If the values are [1,2,3,4], then make it using a loop "1,2,3,4".

Then pass the string.

In teh landing page split the string with "," and you will again get the array.

Hope it helps you.

Thanks

Pass Data Between View and Controller in CodeIgniter, You can pass any number of arrays as parameters to a view; you can also pass Looking at the URI, we will build the controller example2.php with the function Codeigniter, Passing//url parameters to view variable: $rows, value: array('a'� Creates a standard HTML anchor link based on your local site URL. The first parameter can contain any segments you wish appended to the URL. As with the site_url() function above, segments can be a string or an array.


Why don't you use uri segments for array? You can count uri segments and could use them. Even u could check how many arrays already there.

url.com/1/2/3

http://ellislab.com/codeigniter/user-guide/libraries/uri.html

Note: uri segment doesnt work on main controller index function, you have to define another function than index for example: I don't know what it happens but i think because of htaccess file I'm using do remove index.php.

url.com/uri_segment_controller/go/1/2/3

Example 2 – passing the complex parameters to a view , <?php namespace App\Controllers; use CodeIgniter\Controller; class You can get an uppercase version by passing in true as the only parameter: // Returns If you want that converted to associative arrays, pass in true as the first parameter. You can cast this object as a string to get a full URL for the current request:. You might also like: Pass Data From One Function To Another In Same Codeigniter Controller. Conclusion. In this tutorial I have discussed how to pass data from controller to view in CodeIgniter. The process is very simple and you could easily render views through the controller. If you need help, you could add a comment below describing your issue.


IncomingRequest Class — CodeIgniter 4.0.4 documentation, The URL Helper file contains functions that assist in working with URLs. Loading Segments can be optionally passed to the function as a string or an array. Here is a Here is an example of segments passed as an array: The first parameter can contain any segments you wish appended to the URL. As� getUsernames () – Fetch all usernames from the users table and return record in an Array format. getUserDetails () – This method takes a single Array type parameter. If $postData ['username'] is set then fetch a record from the users table where username = $postData ['username']. Return record in an Array format.


URL Helper — CodeIgniter 3.1.7 documentation, Up to now, we previously only called load->view passing it one parameter — the name of the view — such as in the Welcome controller's index that we're passing the load->view function a second parameter: our $data array. a controller, you can omit index from the URL, so the following URL will display the same page: mark_as_flash () function is used for this purpose, which takes only one argument of the value to be stored. We can also pass an array to store multiple values. set_flashdata () function can also be used, which takes two arguments, name and value, as shown below. We can also pass an array.


Loading and Displaying Data in a CodeIgniter View – Self-Taught , The parameters to be passed to the callback, as an indexed array. As of PHP 5.6 you can utilize argument unpacking as an alternative to call_user_func_array � Array Helper¶. The array helper provides several functions to simplify more complex usages of arrays. It is not intended to duplicate any of the existing functionality that PHP provides - unless it is to vastly simplify their usage.