I am among less comfortable and struggle with pset7. I will be grateful for your help and explanation on the following:
Looking at View Source Page of https://ide50-name.cs50.io/register.php
as well as other pages I see that register_form.php code is attached between the code of header.php and footer.php, all of which can be found in Views folder. But I don't understand how this trick works.
There is a function render() in helpers.php, and this function displays contents of register_form.php between the header and footer.
/**
* Renders view, passing in values.
*/
function render($view, $values = [])
{
// if view exists, render it
if (file_exists("../views/{$view}"))
{
// extract variables into local scope
extract($values);
// render view (between header and footer)
require("../views/header.php");
require("../views/{$view}");
require("../views/footer.php");
exit;
}
// else err
else
{
trigger_error("Invalid view: {$view}", E_USER_ERROR);
}
}
1) I am not sure I understand what extract() function does in render(). According to this page, extract() function creates local variables out of variables, which comprise an array. http://www.w3schools.com/php/func_array_extract.asp
But register_form.php
(as well as login_form.php) contain html code and doesn't contain any arrays. So what local variables are being created by extract() in render(), how does extract() work with these html files?
2) Register.php (as well as login.php) call the render() function only in case the method is GET; but if the method is POST, the render() function is not called, but the https://ide50-name.cs50.io/register.php
page's View source code does show register_form.php code between header.php and footer.php. How does that happen?
I will be truly grateful for your help! It is truly difficult for me. Thank you very much!