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

PHP

how can you use a picture as link to call a .twig file

Hey guys, i am trying to create a website to show resorts sites in africa. My problem is i am using composer and have changed all my html files to .twig files. I am trying to call the a .twig file which contains pictures but instead of printing out the pictures its giving me the most popular 404 page not found.

my home twig file is as follows;

{% extends 'main.twig' %}

    {% block content %}
    <section>
    <ul id="gallery">
      <li>
        <a href="templates/Resorts_Sites_in_Africa"><img border="0">
          <img src="img/victoria_falls3.jpg" alt="">
          <p>Resorts Sites in Zimbabwe.</p>
        </a>
      </li>

</ul> </section> {% endblock content %}

my php file is as follows;

<?php

require 'vendor/autoload.php'; date_default_timezone_set('Africa/Harare');

use Monolog\Logger; use Monolog\Handler\StreamHandler;

function phpAlert($msg_error) { echo '<script type="text/javascript">alert("' . $msg_error . '")</script>';

}

//$log = new Logger('name'); //$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING)); //$log->addWarning('Foo');

$app = new \Slim\Slim( array( 'view' => new \Slim\Views\Twig() ));

$view = $app->view(); $view->parserOptions = array( 'debug' => true ); $view->parserExtensions = array( new \Slim\Views\TwigExtension(), );

$app->get('/', function() use($app){ $app->render('home.twig'); })->name('home');

$app->get('/Resorts_Sites_in_Africa', function() use($app){ $app->render('Resorts_Sites_in_Africa.twig'); })->name('resorts');

$app->get('/contact', function() use($app){ $app->render('contact.twig'); })->name('contact');

$app->get('/search', function() use($app){ $app->render('search.twig'); })->name('search');

$app->get('/search1', function() use($app){ $app->render('search1.twig');

$connect=mysql_connect("localhost","root","password"); // Establish a connection mysql_select_db('resorts_africa',$connect); // Name of your DB

if(!$connect) // If connection not established print 'Could not connect to the database'; // Show an error

if(isset($_GET['search'])) // If it's submitted { $inp = Clean($_GET['inpname']); // Clean my input $sQuery="SELECT column FROM table WHERE column LIKE '%".$inp."%' "; // mySql query $r = mysql_query($sQuery) or die(mysql_error()); // If query fail, let me know the error if(mysql_affected_rows()===0) // If no match found echo "{$inp} is not in our database."; // Let me know it is'nt found in the table else { echo "<p>{$inp} was successfully searched.</p>"; // Yes, the query worked while($row=mysql_fetch_array($r)) // Loop through the query results echo "{$row[0]}<br>"; // Show the results } // End of the else statement } // End of the if statement

function Clean($str) // Clean my input { return mysql_real_escape_string(strip_tags(trim($sStr))); // Remove traces of injection } })->name('search1');

$app->post('/contact', function() use($app){ $name= $app->request->post('name'); $age=$app->request->post('age'); $email=$app->request->post('email'); $expected_date=$app->request->post('expected_date'); $country_to_visit=$app->request->post('country_to_visit'); $reason_for_visit=$app->request->post('reason_for_visit'); $payment_method=$app->request->post('payment_method'); $msg=$app->request->post('msg');

if(!empty($name) && !empty($email) && !empty($msg)) { $cleanName = filter_var($name, FILTER_SANITIZE_STRING); $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL); $cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING); } else { phpAlert( "All the fields are needed. Please fill all fields and send again" ); die(); $app->redirect('/contact');

}

$transport = Swift_MailTransport::newInstance('/usr/sbin/sendmail -bs'); $mailer = \Swift_Mailer::newInstance($transport);

$message= \Swift_Message::newInstance(); $message->setSubject('Email From Our Website'); $message->setFrom(array($cleanEmail=>$cleanName)); $message->setTo(array('selesgama@gmail.com')); $message->setBody($cleanMsg);

$result = $mailer->send($message); if($result > 0){

phpAlert(   "Thank you for contacting us. We will get to you soon."   ); 
die();
$app->redirect('/');

} else{ phpAlert( "There was an error sending the message. Try again later." ); die();

} $app->redirect('/contact'); });

$app->run();

?>

the Resorts_Sites_in_Africa.twig is as follows

{% extends 'main.twig' %}

    {% block content %}

<div class="resortsAfrica"> 
<ul id="resorts">
  <li>
    <div class="content-left"> 
    <a href="img/victoria_falls3.jpg">
    <img src="img/victoria_falls3.jpg" alt="">
    </a> 
    </div> 
    <div class="content-right"> 
    <p><b> The Victoria Falls<b></p>
    <p></p>
    </div> 
    </div> 
  </li>


  </ul>
  </div>
    {% endblock content %}

if i clickthe picture on my home page it gives me the following results;

404 Page Not Found The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.

Visit the Home Page

Thanks very much to those who will help.