Codeigniter echo session Multidimensional Array variable - codeigniter

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.

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.

Echo from foreach

i have model that return
return array(
'senin'=> $senin->result(),
'selasa'=> $selasa->result(),
'rabu'=> $rabu->result()
);
and controller
$data['ot'] = $this->genbamodel->getOt();
in my view, i use 'foreach $ot as key' and when i tried to print_r($key) the result like this
Array()
Array ( [0] => stdClass Object ( [id_genba] => 1 [hari] => Tuesday [shift1] => 2 [shift2] => 0 ))
Array ( [0] => stdClass Object ( [id_genba] => 1 [hari] => Wednesday [shift1] => 1 [shift2] => 2 ))
how to get just shift1 = 2 and shift2 = 0 (from second array / hari=>Tuesday ??
Thankyou
I don't think you need the foreach loop to access those values. To get just the second record, you can do the below.
$ot['selasa'][0]->shift1
$ot['selasa'][0]->shift2
$ot['selasa'][0]->hari

how to create 2 variable session in Codeigniter

How to Create 2 variable session
I have create but for $se not show
I think your after something like Multiple session but question unclear
Examples
Backend
$session_vals1 = array(
'some_data' => 1
);
$this->session->set_userdata('backend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('backend');
echo $session_vals1_data['some_data'];
Frontend
$session_vals2 = array(
'some_data' => 2
);
$this->session->set_userdata('frontend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('frontend');
echo $session_vals1_data['some_data'];

Laravel user sessions

How do I distinguish between a session which stores data about a logged-in user, and a session which doesn't have any data about a logged-in user (basically a session which belongs to a logged-out viewer of the page)?
You can check whether a user is logged in via Auth::check
See http://laravel.com/docs/security#authenticating-users
Update
Here's the output of Session::all(). The first one is of a unauthenticated user:
Array (
[flash] => Array (
[old] => Array (
)
[new] => Array (
)
)
[_token] => sqwf2m9vxjePpq0jYWw4Vs16nhXoFBGH4PT14xpm
[language] => de
)
And a authenticated user:
Array (
[flash] => Array (
[old] => Array (
)
[new] => Array (
)
)
[_token] => sqwf2m9vxjePpq0jYWw4Vs16nhXoFBGH4PT14xpm
[language] => de
[login_82e5d2c56bdd0811318f0cf078b78bfc] => 1
)
A look into the source tells us what's going on:
public function login(UserInterface $user, $remember = false)
So there's a way of distinguishing a logged in user from a user "just passing by", of course..

Magento - How to set media gallery images programmatically?

I try to set a new magento product image e.g. che_3.png with:
$visibility = array (
'thumbnail',
'small_image',
'image'
);
$product->addImageToMediaGallery( $file, $visibility, true, false);
The product image is moved from the
temporary directory: /media/tmp/catalog/product/upload/sessionid/original/che_3.png
to the
destination directory: /media/catalog/product/c/h/che_3.png
Now, if i want to call the image filepath - that is saved by magento - is wrong. The media_gallery object looks like this:
[media_gallery] => Array
(
[images] => Array
(
[0] => Array
(
[value_id] => 89
[file] => /c/h/che_3_2_1.png //che_3.svg is already in here
[label] =>
[position] => 1
[disabled] => 0
[label_default] =>
[position_default] => 1
[disabled_default] => 0
)
[1] => Array // why this second item?
(
[value_id] => 88
[file] => /c/h/che_3_2.png
[label] =>
[position] => 1
[disabled] => 0
[label_default] =>
[position_default] => 1
[disabled_default] => 0
)
)
[values] => Array
(
)
)
As you can see the filename is extended by magento and also two items are added to the media_gallery.
My question is how can I reset the product respectively the internal counter so magento is using the original file as it is?
Thanks in advance.
Problem solved: I've saved the product twice with $product->save() and it seems $product->addImageToMediaGallery() is also executed twice.

Resources