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.
Related
How to get the updated session data from a JsonResponse during test, I want to make use of the updated session data to my next series of test.
I am using an api route, when i make use of $response->dumpSession() the session can be traced. But when I make use of $response->getSession()->all to pass this values to my next test request returns me a error.
when I tried to look for the property of the $response cannot find the property of session
Thanks in advance.
There is no getSession method on the TestResponse class. But instead you can use
app('session.store')->all();
to achieve the same thing. This what the dumpSession uses under the hood also.
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.
I have this code retrieved from var_dump($cache) where $cache is the variable holding the object: http://pastebin.com/9Ufpzbdn (Sorry, code is hard to format here but it's not that long).
How do I access property $_redis?
I tried $cache->_redis but it says it's undefined.
I just want to access it so I can use its set and fetch methods.
I have not touched any php for awhile now. Thanks in advance!
I think you can try:
$redis = $cache->getBackend()->_redis;
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)
I am new to codeigniter , In my program i want a variable need to be accessed by multiple controllers,
It's not a constant variable, value of variable changes ,
Sorry , My mistake
I want to store a JSON object to be precise
Pls help me to figure this out.
Thanks in advance.
You can create a base controller with an attribute for your variable, then have your controllers extend that base controller.
Option 1
Since you are using CodeIgniter and sessions then something like this could work out for you:
set it
$someJSONobject = 'JSON';
$this->session->set_userdata('GLOBAL_JSON', $someJSONobject);
retrieve it
$someJSONobject = $this->session->userdata('GLOBAL_JSON');
echo $someJSONobject->subitem;
Make sure you are storing sessions in a DB if you go with this option because Cookie space is VERY limited
Option 2
Even if you are not using CodeIgniters' session implementation then you can do something quite similar in native PHP:
$someJSONobject = 'JSON';
$_SESSION['GLOBAL_JSON'] = $someJSONobject;
Appending on Rooneyl's solution you may want to save that value on session which is easier to access from all end
Session docs