How to run a php function only in detail view but not in list view?
What exactly are you trying to do? The answer to your question may depend on what your requirements are.
I have trying to change the data at the point of detail view but not the list view.
The after_retrieve hook is perfect for this scenario. It doesn't run on the list view. Only the detail and edit views. You can further nail it down to the detail view only by checking the request vars, if you would like.
Yes, i agree, but I would like to update the data first before retieving. So that I could display the newest verion. when I use after_retrieve, it will only display the old version as the hook display the verion "after retrieved".
I'm not following. An after_retrieve hook fires after pulling the latest data from the database so it will be the newest version. If you want to manipulate the data, save it, then pull it for the detail then you can accomplish that in the after_retrieve by doing your function and running a save() on the bean. The latest will then just be there for the detail view. An alternative is to also do this in a before_retrieve hook, but it's the same end result.
Thanks. is there a before_retrieve hook? I think the after_retrieve hook will update the data after retrieve and at the same time display the after_retrieve data which is not update data.
Yes, there is a before_retrieve hook. Same arguments as after_retrieve. The after_retrieve data would contain the latest data, but it depends on how you do it. For example:
Now "latest" will show on the detail view for my_custom_field thus showing the latest data.
Yikes, that's hard to read. I guess the advanced editor isn't formatting the raw HTML option correctly.
But the $bean->my_custom_field = 'latest'; does not show the 'latest', I still have to refresh the page in order to show latest.
BTW, I am using after_retieve hook
Retrieving data ...