Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

.htaccess for custom folder

Hey

How do i make a custom folder, that ignores the /public folder

So let's say my folder structere is like this:

app/
public/
themes/

How do i do so, that in themes/css/ gets ignores by the public rule in htaccess.. So if i access themes/css/ and then make it not look for the folder inside public, but in themes

You have to move themes into public so the web server can see it

Is it a bad idea to have .phtml files inside the public folder?

Yes, it's a bad idea, you should only place static assets in public/



36.3k

I'm not sure, but you can see in wordpress they put all code in public config to nginx :)

Is it a bad idea to have .phtml files inside the public folder?

So i would have to make two folders every time i add a theme to my website script

Like so views/themes/default/index.phtml and in public/themes/default/assets/css/style.css

Is there no way to make it the same folder??



30.7k

Hi,

If you want to keep all files (phtml view and assets) in a given theme folder, you can use a function to register your assets automatically in public folder, something like the one used by phalcon-devtools: https://github.com/phalcon/phalcon-devtools/blob/master/scripts/Phalcon/Web/Bootstrap.php

And use it like this:

        $bootstrap = new Bootstrap();
        $bootstrap->install($path);

No i just wanted to make a /themes/ folder on the root ..

But thanks for the link and you reply anyway :-)

edited Sep '15

You could do something like this:

  1. Add another php script to your /public folder, like theme.php
  2. Modify your .htaccess rewrite rules so \.(css|js|png|jpg|...)$ points to theme.php with the original URL as parameter.
  3. Pass through your static files in /themes/whatever/... through theme.php

    It will create some extra overhead though...

edited Sep '15

Doing all that seems so daunting... why not just put the themes inside the public folder and use a js script to load which css and js you need in the view?

edited Sep '15

Because views most often contain sensitive data and/or project layout info, and altough you can block them by properly setting up your webserver, it's still a better idea not to keep them in the public folder. Loading views wth JS is a horrendous idea, because it requires them to be publicly servable. Not to mention that it's impossible, because the dependencies would not be loaded.

Oh right. You can only do so with a php script. My bad and thanks for clarifying.

Because views most often contain sensitive data and/or project layout info, and altough you can block them by properly setting up your webserver, it's still a better idea not to keep them in the public folder. Loading views wth JS is a horrendous idea, because it requires them to be publicly servable. Not to mention that it's impossible, because the dependencies would not be loaded.

So if i wanna do it the safest way, i have to do this:

/public/themes/default/css/style.css /themes/default/index.phtml

Is this correct?

When i pick a theme view in the controller i use $this->view->pick('../../themes/default/index');

It's just frustrating not to have them in the same folder.. :-)

edited Sep '15

Yes, something like that. Also keep in mind that the view service cannot load files outside of the directory specified with $view->setViewsDir(/some/path); and view->pick() will start from that directory.

Frustrating it may be, but that's the safe way ;]

Okay it's working now and i've got the files in seperate folders :-)

Thanks for all the help!



38.2k
Accepted
answer

Accept an answer, so the thread will be marked as solved!

Doesn't matter whom, you can also accept your own :]