multiple input arrays codeigniter - codeigniter

i have a problem in codeigniter project .
codeignter has filter and delete keys of array and also some value .
my html is
<input type="text" name="n['rrr'][]">
<input type="text" name="n['rrr2'][]">
and php code
echo "<pre>";
print_r($_POST['n']);
echo "</pre>";
and also i add same code to begin of index.php in the root path
result is
Array
(
['rrr'] => Array
(
[0] => llll
)
['rrr2'] => Array
(
[0] => kkkkkk
)
)
Array
(
[0] => Array
(
[0] => kkkkkk
)
)
array 1 is showed from index
and second from the controller .
and thanks .

<input type="text" name="n[rrr][]">
<input type="text" name="n[rrr2][]">

Related

how to extract a specific link value (page number) from a pagination in codeigniter?

i would like to extract the current link value from my codeigniter pagination in the controller and put it in a own variable.
the usual pagination code...
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links );
with print_r($data["links"]); i printed the array to check what i find inside.
result:
( Array ( [0] => [1] => 1234NextLast › )
( Array ( [0] => Previous1 [1] => 2345NextLast › )
( Array ( [0] => Previous12 [1] => 3456NextLast › ) and so on
i would like to extract the current page number and add it to a different variable.
... [1] => 1
... [1] => 2
... [1] => 3 and so on
You can get current page number from the url:
$this->uri->segment(3);
If it is in the third segment, you can count the segments or i prefer this:
$segment_array = $this->uri->segment_array();
$last_segment = end($segment_array);
And last segment should be your current page number.

PHP read array declaration from file?

I've got a text file with an array declaration (actually an array of arrays) that I'm reading into my PHP using 'file_get_contents'. The PHP code is treating the contents that it reads from the file as a literal string, rather than creating an array. I need to actually create the array.
Example:
The file 'probe2.csv' contains the following text:
array(array(22, 296), array(43, 667), array(64, 1008), array(84, 1273), array(105, 1520), array(126, 1899), array(146, 2149))
My PHP is:
$s1 = array(array(22, 256), array(43, 524), array(64, 797), array(84, 1133), array(105, 1515), array(126, 1813), array(146, 2128));
$s2 = file_get_contents('probe2.csv');
print_r($s1);
echo "<p>";
print_r($s2);
echo "</p>";
The output is:
Array ( [0] => Array ( [0] => 22 [1] => 256 ) [1] => Array ( [0] => 43 [1] => 524 ) [2] => Array ( [0] => 64 [1] => 797 ) [3] => Array ( [0] => 84 [1] => 1133 ) [4] => Array ( [0] => 105 [1] => 1515 ) [5] => Array ( [0] => 126 [1] => 1813 ) [6] => Array ( [0] => 146 [1] => 2128 ) )
array(array(22, 296), array(43, 667), array(64, 1008), array(84, 1273), array(105, 1520), array(126, 1899), array(146, 2149))
I'm a bash guy, not a PHP guy, so I have no idea how to do this.
To make it work, you should you need to change it like this:
<?php
$s2 = array(array(22, 296), array(43, 667), array(64, 1008), array(84, 1273), array(105, 1520), array(126, 1899), array(146, 2149));
And then, in you main php file, just include it:
include('probe2.php');
If you have no control about the probe2 file, you can do this (it's bad practice, but works):
$temp = file_get_contents('probe2.csv');
eval('$s2 = ' . $temp . ';');
$s2 will have the right array from here.

Laravel overwrite value in request

I trouble to overwrite existing request value.
Below example info is my input array and product is my input array key.
e.g,
HTML
<input type="text" name="info[product]" value="10" />
PHP
echo request('info.product');
OUTPUT
10
Edit
print_r(request()->all());
Array
(
[info] => Array
(
[product] => 10
)
[_method] => PUT
[info.product] => 20
)
Question : But now I am required to overwrite this default 10 value to 20 using laravel.
Use the merge() method:
$array['input']['product'] = 20;
request()->merge($array);
Or do this when you'll need the data from request:
$data = request()->all();
$data['input']['product'] = 20;
Try this:
Input::merge(['input.product' => 'new value']);
and don't forget to import Input facade at the top.( use Input;)

Looping issue in Tinybutstrong

I've the data structures as shown below
Array
(
[0] => Array
(
[name] => dummy0
[projects] => Array
(
[project_names] => project0
[dates] => Array
(
[0] => 5
[1] => 11
[2] => 28
)
)
)
[1] => Array
(
[name] => dummy1
[projects] => Array
(
[project_names] => project1
[dates] => Array
(
[0] => 10
[1] => 12
[2] => 28
)
)
)
)
I'ld like to get the output as following format
dummy0
Project0
5
11
28
dummy1
Project1
10
12
28
I've used below snippet but didnt get the oupput as I excepted
[replies;block=begin;sub1=projects]
[replies_sub1.val;block=tr;sub1=dates]
[replies_sub1_sub1.val;block=td]
[replies;block=end;comm=text:p]
Any kind of help will be appreciated
The problem is that your sub-data dates is actually under 2 levels of columns: projects/dates. And TBS does not support such data structure for the automatic sub-block.
The solution is to change your data structure in order to have it like this :
(
[0] => Array
(
[name] => dummy0
[dates] => Array
(
[0] => 5
[1] => 11
[2] => 28
)
....
)
....
If you cannot change the structure, you can simply use parameter ondata with a custom function that will create a new (virtual) column in your data.
PHP:
function f_ondata($BlockName,&$CurrRec,$RecNum) {
$CurrRec['dates_z'] = $CurrRec['projects']['dates'];
}
HTML:
<div style="border: solid 1px red;">
[replies;block=begin;sub1=dates_z;ondata=f_ondata]
<table border="1">
<tr>
<td>
[replies.projects.project_names]
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
[replies_sub1.val;block=tr]
</td>
</tr>
</table>
<text:p> [replies;block=end;comm=text:p] </text:p>
<div>

Codeigniter echo session Multidimensional Array variable

Okay im using codeigniter and i got a session where i want to echo [user_id], i can see its an "Multidimensional Array", but i cant seem to get it right...
This is the print_r from all session userdata:
Array (
[session_id] => b7e721332248
[ip_address] => ::1
[user_agent] => Mozilla/5.0
[last_activity] => 1409104940
[user_data] => [name] => 2 [uniq] => 2
[flexi_auth] => Array ( [user_identifier] => mail.com [user_id] => 2 [admin] => 1
[group] => Array ( [3] => Master Admin )
[privileges] => Array ( )
[logged_in_via_password] => 1
[login_session_token] => 11017021313jhbjh1h2j3b213mab913269d95 ) )
if i type:
print_r($this->session->all_userdata()); // i will get all
echo $this->session->userdata('uniq'); //returns 2
echo $this->session->userdata('user_id'); //returns nothing(THIS IS THE PROBLEM)
Ive tried something like this:
$this->session->userdata(1,1); //1,1 would be array 2 and number 2 which would be user_id
Is it because i can only print out if I loop through them somehow?
You're trying to call the data directly, if you're want to access user_data or flexi_auth you need to assign the data to a variable then target it since they're arrays.
$session_data = $this->session->all_userdata();
echo $session_data['user_data']['uniq']; // 2
$user_data = $this->session->userdata('user_data');
echo $user_data['uniq']; /// 2
$flexi_auth = $this->session->userdata('flexi_auth');
echo $flexi_auth['user_id']; /// 2
If you're trying to target a string directly
echo $this->session->userdata('last_activity');
You can simply access user name stored in session like this
echo $this->session->userdata['user_data']['name'];
Be sure you have some userdata in session or use like this to avoid any errors
echo #$this->session->userdata['user_data']['name'];
adding # does not generate any errors. hope you got the answer you were looking for.

Resources