The code for the returned values of the F method in the TP framework is actually very simple. I read data from the database and then cache the data to the file using the F method. data is written when the file is created, however, the return value of the F method is NULL.
Public function updateCache () {$ db = M ('Category '); $ data = $ db-> select (); $ f = F ('data', $ data) var_dump ($ f); // The output is null}
In fact, I just want to use the return value of the F method to determine that the cache is successful... this is my purpose... but I have been looking for a long time and I don't know why the F method returns NULL.
Reply to discussion (solution)
No! Post your F function definition
No! Post your F function definition
Is the latest version of the TP framework F function... boss
Can't you post it? And I want to download one?
Can't you post it? And I want to download one?
Function F ($ name, $ value = '', $ path = DATA_PATH) {static $ _ cache = array (); $ filename = $ path. $ name. '. php '; if (''! ==$ Value) {if (is_null ($ value) {// delete cache if (false! = Strpos ($ name, '*') {return false; // TODO} else {unset ($ _ cache [$ name]); return Think \ Storage :: unlink ($ filename, 'F') ;}} else {Think \ Storage: put ($ filename, serialize ($ value), 'F '); // cache data $ _ cache [$ name] = $ value; return ;}// obtain cache data if (isset ($ _ cache [$ name]) return $ _ cache [$ name]; if (Think \ Storage: has ($ filename, 'F') {$ value = unserialize (Think \ Storage :: read ($ filename, 'F'); $ _ cache [$ name] = $ value;} else {$ value = false;} return $ value ;}
F function reads data from the cache, and writes data to the cache to return null.
Want data? $ Data = F ('data ');
F function reads data from the cache, and writes data to the cache to return null.
Want data? $ Data = F ('data ');
public function put($filename,$content,$type=''){ $dir = dirname($filename); if(!is_dir($dir)) mkdir($dir,0755,true); if(false === file_put_contents($filename,$content)){ E(L('_STORAGE_WRITE_ERROR_').':'.$filename); }else{ $this->contents[$filename]=$content; return true; } }
This is the Put method that should be called. if it succeeds, true is returned.
17 rows return;
It is wrong to return null! They are too careless.
Return by lower version, should be written
Return strlen ($ value );
17 rows return;
It is wrong to return null! They are too careless.
Return by lower version, should be written
Return strlen ($ value );
Boss, why does it return null after I modify it as you wrote?
8 rows return false; // TODO
11 rows return Think \ Storage: unlink ($ filename, 'F ');
17 rows return
22 rows return $ _ cache [$ name]
29 rows return $ value;
Isn't it returned? Based on your input parameters, do you know what the problem is after manual derivation?
8 rows return false; // TODO
11 rows return Think \ Storage: unlink ($ filename, 'F ');
17 rows return
22 rows return $ _ cache [$ name]
29 rows return $ value;
Isn't it returned? Based on your input parameters, do you know what the problem is after manual derivation?
The reason why strlen returns Null is that $ value is an array.
Think \ Storage: put ($ filename, serialize ($ value), 'F'); true is returned
I Think you should directly return Think \ Storage: put ($ filename, serialize ($ value), 'F'); can this be modified?
8 rows return false; // TODO
11 rows return Think \ Storage: unlink ($ filename, 'F ');
17 rows return
22 rows return $ _ cache [$ name]
29 rows return $ value;
Isn't it returned? Based on your input parameters, do you know what the problem is after manual derivation?
Looking at the official function, it seems that if the cache is successful, a null value is returned...
You can directly return $ value.
However, $ value may have a lot of content, but you don't need it.
Therefore, return is also supported! Empty ($ value );
Since it is a write cache, $ value indicates the written content.
If it is not null, the operation is successful.
In short, what is returned depends on your existing algorithm.
TP is just a tool, which allows him to adapt to you, not to accommodate him.
You can directly return $ value.
However, $ value may have a lot of content, but you don't need it.
Therefore, return is also supported! Empty ($ value );
Since it is a write cache, $ value indicates the written content.
If it is not null, the operation is successful.
In short, what is returned depends on your existing algorithm.
TP is just a tool, which allows him to adapt to you, not to accommodate him.
Well, when I use the framework, I always feel that the people I write are different from what I think. the boss is right! Thank you!