Cakephp and webroot

I am mainly a database person, not framework. I am trying to figure how exactly cake handles the “not showing” of webroot folder. For example I have some images under webroot in a subfolder named upload. And under upload more folders with images. My testsite name is just called cakephp for now, will change later. Now in the browser if I right click image in firefox and view image it shows


But rover.jpg is at public_html\cakephp\webroot\upload\imgdogs\rover.jpg
How is cakephp doing this, (not showing /webroot in url) I am trying to learn how it’s done…

To add I made a constant in paths .php

define('DIR', '/cakephp/');

so in view I can simply

$linev = $linev . '<img src="' . DIR . 'upload/imgdogs/' . $row->dogpic . '" alt="" class="image"></a></td>';

But still doesn’t help explain how cake bypasses showing webroot, thanks

Edit: I noticed that

$linev = '<td class="imgtd"><a href="' . DIR . 'dog/view?dogid=' . $row->dogid . '">';

links to correct results which is


BUT testing and taking out DIR temp substitute “”

$linev = '<td class="imgtd"><a href="' . "" . 'dog/view?dogid=' . $row->dogid . '">';

Doesn’t work I get this


dog/ twice. But this

$linev = '<td class="imgtd"><a href="' . "" . 'view?dogid=' . $row->dogid . '">';

works, so here taking DIR out and dog/ automatically knew I needed dog/

You see the confusion, how does cake know I need dog/ added? the route to the view is

$routes->connect('/dog/view/', ['controller' => 'Dogs', 'action' => 'view']);

The not showing webroot trick is done by the .htaccess in the main directory and in the webroot directory (that only works with apache, for others you should configure in its own way)

You don’t need to redefine the directories. That’s when you are not using the default app folder structure (like having the cakephp core in another directory than the src/config)

And last, for links you should generate urls with the Helper