We just finished a major project 2 days after its deadline. By we, I meant me (fumbling to understand what is going on in this program) and my boss (who instructs me most of the way).
What the client wanted in the program: When a person approves a request made to him, that request in csv format will download automatically to a different server's folder.
What I don't understand (not yet anyway): How to download csv file to a specific folder.
After a bunch of trial and errors, and hints from StackOverflow, I got cURL. With cURL, I was able to download a csv file whenever I went to its web link. That csv file saves to wherever the cURL file was located. From now on, I'll call this file with cURL in it as listen.php.
Yey! Atleast I know that listen.php really downloads something.
The next problem: I need to pass dynamic data to that csv. As it is, it is only accessible when I go to the page directly, where listen.php is, and the csv just inputs 302 error.
So I need to POST from my controller the data to that listen.php file. That listen.php file will then go to the link, and hopefully download the correct csv file. My problem was in the sending part: how do I send $_POST data without a form, or submit button or js?
Boss' advice: Research guzzle.
And I said: (verbatim in Tagalog: "Tama ba pagkakaintindi ko sir? Magpopost ako from my controller to listen.php?") Do I understand it correctly? I will post the data from the controller to listen.php?
He replied: Yes, that's correct. "Yes". (Tama daw.)
After reading the request part of Guzzle docs, and copying and modifying its sample code, I was able to pass data to listen.php. Yey! And that file downloads. I know the data I passed was correct because the csv file's name was correct and dynamic. I passed the title of the csv in the POST request as well.
But inside that csv was a bunch of different errors.
The next problem: So I was able to download a csv file, but this file only contained:
a) blank page
b) 302 redirect error
c) csv file but contained html code with stacktrace of errors
I tried a few different things, of which I forgot which specifically, which resulted to the 3 kinds of errors I had.
I have a tendency to run AWAY from errors. Whenever I couldn't understand a specific set, or I'm stuck on a task, I go to another task down the list. I don't think it's efficient but I just feel better when I get a task done, even if it's a easy or minor one.
I think this is mainly why I take longer on projects. I tend to have a bunch of hard problems to solve whenever the deadline is nearing.
This creates more panic.
Then I can't think properly and be focused because I am worrying on the deadline nearing and I can't solve it.
Deadly cycles continues.
And when I got the csv file with the stacktrace errors, my instinct was to try another "hack" I found in StackOverflow, instead of finding the error in the stacktrace.
Do I wish to have errors pop out, or have a blank page that doesn't have errors (but is still not working) instead? I'll opt for the error page anytime. But they still scare me.
My boss said it would be good if the errors blow up so we could see the errors. Atleast then we have a clue where to look.
I feel like an investigator Detective Conan. But instead of dead bodies, I find pages not working and why.
How do you feel about errors in your program?