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 trial


Mayur Pande
Mayur Pande
Courses Plus Student 11,711 Points

How to return variables in using silex

I have a function for a password reset which checks up the db whether or not the timestamp has passed or not. If it hasn't it should return the get variables passed into the function as an array to be used in the twig view and in the controller render the appropriate twig file. However at the moment I keep getting the error

Impossible to access an attribute ("email") on a string variable ("mayurpande.uk@gmail.com") in "confirm-new-password.twig" at line 45

Here is what the code for this part looks like in my twig file;

<form class="form-signin" action="/confirm-new-password" method="post">
<h2 class="form-heading">Confirm New Password</h2>
<label for="inputNewPass1" class="sr-only">New Password</label>
<input type="password" id="inputNewPass1" class="form-control" name="pass1" placeholder="New Password" required>
<label for="inputNewPass2" class="sr-only">Re-Type New Password</label>
<input type="password" id="inputNewPass2" class="form-control" name="pass2" placeholder="Re-type New Password" required>
{% for items in test %}

<input type="hidden" name="email" value="{{ items.email }}">
<input type="hidden" name="token" value="{{ items.token }}">
{% endfor %}
<div class="spamCheck">
    <label for="inputPostcode" class=sr-only">Postcode</label>
    <input type="text" id="inputPostcode" class="form-control" name="postcode" placeholder="Leave this field blank" />
<button class="btn btn-lg btn-default btn-block" type="submit">Reset Password</button>

here is the code for my controller

$app->get('/confirm-new-password/{email}/{token}', function($email,$token) use($app) {
    $test = $app['auth']->get_token($email,$token);

    if (null !== $test){
        return $app['twig']->render('confirm-new-password.twig', array('active_page' => 'confirm-new-password', 'is_user_logged_in' => $app['auth']->is_user_logged_in(), 'items' => $app['tutor']->get_user_id(), 'test' => $test));
        return $app->redirect('/');


and here is the code for my model

    public function get_token($email,$token){
        $email = mysqli_real_escape_string($this->link, $email);
        $token = mysqli_real_escape_string($this->link, $token);

        $result = mysqli_query($this->link, "select email, token, expirytime from user where email = '{$email}'");

        $row = mysqli_fetch_assoc($result);

        $time = strtotime($row['expirytime']);

        $curtime = time();
        $userResetDets = array($row['email'],$row['token']);
        if($token === $row['token'] && (($curtime-$time)  < 60)){
            return $userResetDets;
            $res = mysqli_query($this->link,"update user set token='' and expirytime='' where email = '{$email}'");
            return null;


    public function get_user_id(){
        $result = mysqli_query($this->link, 'select email from user');

        while($row = mysqli_fetch_assoc($result)){
            foreach($row as $item){
                $items = $item;