Skip to content
bcosca edited this page Feb 14, 2013 · 20 revisions

Where can I get more help?

Should I use the static calling convention (F3::xxx) or call an instance of F3 (like $f3->xxx)?

Static method calling convention has been deprecated. It will be dropped in the next major version.

Should I use the static calling convention (F3::xxx) or call an instance of F3 (like $f3->xxx)?

Static method calling convention has been deprecated. It will be dropped in the next major version.

Can I run F3 in a sub-directory?

Well, best practice is to run F3 on your own virtual host, so that it's always the root of your domain. But in some cases, when working on a server, where F3 is not located in the web root, i.e. on shared webhosting services, where you possibly don't have the choice to setup vhosts or for testing purpose, you might need some extra workarounds.

Let's say F3 runs in mydomain.com/myapp/. Maybe you think you need to update your .htaccess file now and add a RewriteBase /myapp, but as long as the .htaccess file is also located where the index.php is, you don't need to add it, because the server will take the current path as Base by default.

But you will notice some weird behaviours with your pagelinks. When you are on mydomain.com/myapp/page1/ and click a link like <a href="page2/">, it goes to mydomain.com/myapp/page1/page2/ instead of the desired mydomain.com/myapp/page2/. Well you could add a leading slash to your links like /page2/, but then it becomes an absolute link that goes to mydomain.com/page2/ and fixing that by adding the app-path to each link in your template, like href="/myapp/page2/", just feels crappy.

The solution to this is using the HTML Tag. Just add it in the head section of your template, like <base href="myapp/"> (with tailing slash). Your links will now behave correctly. Unfortunately the Internet Explorer browser only supports absolute paths as base href value. But adding <base href="http://mydomain.com/myapp/"> is not that comfortable, as you might need (switching dev and live server, http / https). So, to get a bit sugar on this, KOTRET was so friendly and wrote this little snippet, that automatically computes the absolute base path. Just put that in a Utils class and add <base href="{{ Utils::getBaseUrl() }}"> to your template. Now it's fine. The base tag also affects CSS links you might have used in a relative way, like background-image: url(../img/page_bg.jpg). They are also working like expected now.

Clone this wiki locally