We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Problem using CI Sessions in EE Plugin

Development and Programming

IOS Admin's avatar
IOS Admin
33 posts
14 years ago
IOS Admin's avatar IOS Admin

This is my first time using EE or CI. I need to create a multi-page form to allow users to configure and purchase a service from our company. My initial research indicated that there isn’t anything ready-made to do such a thing so I realized I needed to build my own. Which is fine as I like having that level of control. The downside is I have a learning curve to deal with along with a deadline. 😊

So, I decided to create a plugin (a module seemed overkill since this was single use). Since this is a multi-page form I wanted to use a session to store data between pages. However as I started to code this up I found a potential problem.

It appears that I cannot use the set_userdata method of the CI Session class. When I try I get this error.

Fatal error: Call to undefined method EE_Session::set_userdata()

This was my code:

$this->CI->session->set_userdata('vl_form_data', $form_data);

What I notice in the error is that EE seems to actually be handling the sessions. Second, EE’s Session class must not have the “set_userdata” method.

Am I doing something wrong? What are my options? Any pointers on multi-page forms in a plugin with CI and EE?

       
Victor Michnowicz's avatar
Victor Michnowicz
95 posts
14 years ago
Victor Michnowicz's avatar Victor Michnowicz

Try using “EE” instead of “CI”.

       
IOS Admin's avatar
IOS Admin
33 posts
14 years ago
IOS Admin's avatar IOS Admin
Try using “EE” instead of “CI”.

elvicmic, Thank you. I have not tried what you suggest, because I am on a deadline and have decided to move ahead with using the standard PHP session and it is working well.

However, I did look into the EE Session Class and I do not see the set_userdata() method nor is it in the documentation, so I am assuming now that using EE would not help. Maybe in the future I can get back to checking this out.

       
Victor Michnowicz's avatar
Victor Michnowicz
95 posts
14 years ago
Victor Michnowicz's avatar Victor Michnowicz

Ahh, yeah the EE sessions are kinda weird. Something like this may work:

$this->EE->session->userdata['my_session_data_key'] = 'My session data value';
echo $this->EE->session->userdata('my_session_data_key');
       
carvingCode's avatar
carvingCode
380 posts
14 years ago
carvingCode's avatar carvingCode

elvicmic’s suggestion doesn’t work.

What is the correct way to set session cookies within a EE addon?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
What is the correct way to set session cookies within a EE addon?

Try this:

$this->EE->functions->set_cookie($name, $value, $seconds);

http://ellislab.com/expressionengine/user-guide/development/reference/functions.html#set-cookie-name-string-value-string-expire-int

       
carvingCode's avatar
carvingCode
380 posts
14 years ago
carvingCode's avatar carvingCode

Thanks, Erik. Just getting back to this after holiday.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.