Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialROBERT RUBY II
10,586 PointsWhere is $this coming from? There is not object I see but $app?!
if( !empty($args['name']) && !empty($args['email']) && !empty($args['msg']) ) {
$mail = json_encode([$args['name'], $args['email'], $args['msg']]);
$container->get('logger')->notice($mail);
// Get named route 'thankyou' from below
$url = $this->router->pathFor('thankyou');
//return $container->get('view')->render($response, 'thankyou.phtml', $args);
return $response->withStatus(302)->withHeader('Location', $url );
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, ROBERT RUBY II ! If you go back to index.php
inside your public folder you should find a line that looks like this:
$app = new \Slim\App($settings);
That creates a new instance of the Slim app and sends in some settings. Later on, in your routes.php
file you will be using the ->get
and ->post
methods on that $app
instance. Thus, $this
refers to the instance of \Slim\App
that you made way back when
Hope this helps!
Dario Preglej
9,771 PointsHow $args['error'] become $error?
if (isset($error)) { echo "<div class='alert alert-danger' role='alert'>ERROR!!! $error</div>"; }
Jennifer Nordell
Treehouse TeacherHi there, Dario Preglej! When you're rendering a template in Slim or "view", you can choose to send in data to that view in the form of an associative array. And you can send anything you like. Whatever you send in those $args
will then become the name of a variable inside the view. So if I sent $args['student'] = 'Dario'
, then I would expect my view to see $student
as a variable and the value as "Dario".
Hope this helps!
edited for additional information The name of the key becomes the name of the variable once it's in the view. It's part of the magic
ROBERT RUBY II
10,586 PointsROBERT RUBY II
10,586 PointsOh. Ok. lol I was very confused.