I controller i can get $_SESSION['my_var'] ( it was created outside of symfony application, and i need to get it inside symfony controller in symfony way e.g.
$Request->getSession()->get('my_var')
But this code always return NULL and if i use $_SESSION['my_var'] i get my result.
I have found PHPBridgeSessionStorage class but this not work for me, because my session already started.
So question is how can i get it with symfony functions?
After some research i have found solution:
$_SESSION['_sf2_attributes']['my_var']
So now i can get access to my variable like this:
$Request->getSession()->get('my_var')
Symfony2 Session stores all values per default under a storageKey "_sf2_attributes" (Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag)
Related
I have following project hierarchy
/Project
/userloginform.php
/CodeIgniter
I am setting my session values inside userloginform.php.
I want to access these values inside codeIgniter Controller.
I found solution for accessing the session in opposite case here.
How can I access them inside codeIgniter?
First load library into your codeigniter controller
$this->load->library('session');
now you can access session object with,
$this->session
and then get your session data using
$this->session->item
Here item is the array name or variable name which contains data that i have stored using session.
You can access session value using both way:
$_SESSION['your_sessioni_key'];
$this->session->userdata('your_session_key');
First one is regular php format. Second is Condeigniter style. Both will give you same output.
It seems like Codeigniter reset the $_SESSION variable set by userloginform.php. Consider this answer.
I am a Java developer (I often used Spring MVC to develop MVC web app in Java) with a very litle knowledge of PHP and I have to work on a PHP project that use CodeIgniter 2.1.3.
So I have the following doubt about how exactly work this controller method:
So I have this class:
class garanzieValoreFlex extends CI_Controller {
.....................................................
.....................................................
.....................................................
public function index() {
$this->load->model('Direct');
$flagDeroga = "true" ;
$this->session->userdata("flagDeroga");
$data = $this->session->userdata("datiPreventivo");
$this->load->model('GaranzieValoreFlexModel');
$data = $this->session->userdata("datiPreventivo");
$this->load->model('GaranzieValoreFlexModel');
$this->load->view('garanziavalore/index_bootstrap',$data);
}
}
I know that the index() method of the garanzieValoreFlex controller class handle HTTP Request toward the URL: http://MYURL/garanzieValoreFlex and show the /views/garanzievalore/index_bootstrap.php page.
It works fine. The only think that I can't understand is what exactly does this code line:
$data = $this -> session -> userdata("datiPreventivo");
Can you help me what exactly is doing? I think that it is putting something into the HttpSession or something like this but I am absolutly not sure about it and I can't understand the logic.
session is a Codeigniter (CI) library (class) that allows data to persist across multiple page calls from a browser. In the version of CI you are using "native" PHP session functionality is not used. But CI's session class does mimic PHP's session in that data is stored in a PHP associative array.
The class has many different methods to store and retrieve user defined data. The function userdata("index_to_data") is one of the main class methods. It is used to retrieve data that has been stored in the session class.
The argument passed to userdata() is the key to a value in the session class array $userdata. So, $this->session->userdata("datiPreventivo"); returns the value stored at $userdata["datiPreventivo"]. If the key (in this case "datiPreventivo") does not exist then $this->session->userdata("datiPreventivo") returns FALSE.
Somewhere in the code you are working with you will find a line where data is stored in the session. The line of code might look something like this.
$newdata = array("datiPreventivo" => $something_value);
$this->session->set_userdata($newdata);
Searching your code for "$this->session->set_userdata" might be helpful to understand what exactly is being saved for future page loads.
It is important to know that CI's session class was completely rewritten in versions > 3.0 so the current documentation may not be very helpful to you. You will need to find the documentation for the version you are using to learn more about the session library. I believe that documentation is included in the download for your version which can be found here.
It is tricky for me since I'm a newbie to cakephp.
So, the problem:
I have a cookie called "userClick" which I store through jQuery. But I need to read it in some cases in cakephp. The problem now is that cakephp doesn't recognize it.
If I use $_COOKIE it works fine but with var_dump( $this->Cookie->read('userClick')) I get an empty array, is there something to do?
Try adding 'Cookie' to your components (in the controller class, a parameter should be named components):
var $components = array('Cookie');
See here: http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Cookies.html
I'm working on moving to CakePHP v2 from v1.3.
In my old 1.3 model I had some local variables which a loadData() function set, and then I could retrieve using a get function.
In v2 I get:
Indirect modification of overloaded property [...] has no effect
I've searched but it isn't related to the data/request->data changes.
Any ideas on how to set these local variables?
Thanks in advance!
Are you sure you updated any code that you are trying to assign values to the $this->data array
to $this->request->data ?
You can no longer assign manually $this->data['newthing']['here'] any more in 2.0
It must be $this->request->data['newthing']['here'] or unset $this->request->data['currentthing']['here'] etc etc
https://groups.google.com/forum/?fromgroups=#!topic/cake-php/Sa-2m95CezM
Like the others said, however, some code would be nice if you have the time. Thanks.
I'm experiencing a problem with symfony's session values handling.
Basically, the problem is this, I have a action filter activated that takes the values of the module and action executed and stores them in the session superglobal.
This is my filter's code:
<------BEGIN CODE---------------->
class getPrevModuleActionFilter extends sfFilter
{
public function execute ($filterChain)
{
//---------------Code to execute *BEFORE THE ACTION* execution---------------
if ($this->isFirstCall()) # Execute this filter only once
{
// Filters don't have direct access to request & user objects => Use context object to get them
$request = $this->getContext()->getRequest();
$user = $this->getContext()->getUser();
if($request->getParameter('action') !== "setCulture")
{
$_SESSION['prev_module'] = "M=".$request->getParameter('module');
$_SESSION['prev_action'] = "A=".$request->getParameter('action');
}
}
//---------------Execute next filter in the chain---------------
$filterChain->execute();
//---------------Code to execute *AFTER THE ACTION* execution, before the rendering---------------
//(...)
}
}
<------END CODE---------------->
The weird thing is that if I do a print_r on the front web controller at the very last minute I see that:
When an action that's not 'setCulture' all goes well (ie, the session gets previous module and action as it should)
When action 'setCulture' gets executed: Symfony stores following values in session:
Array (
[prev_module] => M=
[prev_action] => A=
(etc)
)
ie, it looses the values of session for those 2 entries.
I tried using different namespaces, I tried using symfony's setAttribute from sfUser to handle session values. At the end I tried the raw session handling of PHP. Apparently it seems that the shutdown methods of the factories related to user and storage of session values mess up the session values!
I need your help, please.
SPECS:
Symfony version: 1.4.6
PHP: 5.3
I have Symfony's cache disabled
I'm running the code with the frontend_dev.php controller
Well, I guess Symfony messes up SESSION and COOKIES when used in filters.
I ended up creating my own filter mechanism that performs actions for an entire app.
So, to clarify, my choice was:
create a class autoloaded in root lib folder, that has a static method called 'fe_app_init'
add a preExecute method to the actions of each module in FE app that uses fe_app_init from that class
Now the fe_app_init() handles the values in SESSION rightfully.
It's a shame that Symfony 1.4 has a tool such as filters but then messes up SESSION and COOKIES handling in those.