Tip:
Highlight text to annotate it
X
>> SPEAKER: Let's allow the user to look up information about a given stock.
For quote, we want to display a form so that a user can input the stock
that they want information about.
Then we'll retrieve the stock quote and display it for them.
So let's display a form that allows the user to input a given stock symbol
that they want to look up, which means that we'll want to make a form within
a quote template, perhaps quote_form.php.
>> And the action of that form?
Well, we'll want to send that submission to the controller, perhaps
quote.php, within the public directory.
Then afterwards, we'll retrieve that stock quote.
The function lookup passing in the string of a symbol, that will return
an associative array with index names, symbol, name, and price.
>> Now that we've looked to the stock up, let's display it.
Now, displaying indicates that we should have another template.
We already have quote_form.php as a template, and then we have a
controller quote.php.
But now we're displaying something different in a
slightly different format.
>> So let's create another template perhaps quote.php but within the
template's directory.
At minimum, just display the quote.
But you'll only want to display the quote as long as the stock is valid.
So if it isn't valid, then you'll want to apologize as usual.
>> To print the price of a quote, you can just use this string here.
But you do need to format to two to four decimal places.
So look into the function number_format for how to do that.
With that, you've displayed a quote for the stock that
the user has suggested.