in my grails application I would like to make all files in a specific folder in my web-app directory to be public so I can use them whenever I want. Is this possible when messing around with ApplicationResources.groovy config or is there any other smart way to make them public without calling them directly?
I imagine something like this: resource url:'images/flags/*'
Apparently the Resources plugin does not have this feature, see Resources Plugin -- How To include all contents in a directory?.
The linked post does, however, include a solution.
Related
When we setup laravel, the default url will have "public" on it.
Example : localhost/laravel/public/users
We know that we always wanted to remove the "public" in our url specially when we go to production.
I searched in the internet and looks like removing the "public" url needs some work to achieve like moving files to other folder, modifying .htaccess, etc...
My question is, whats the purpose of "public" url?
Why doesnt laravel provide an easy way of removing the "public" url..
I know Laravel is popular these days but why give beginners a headache in just removing a part of the url?
Let me know your thoughts
The public directory holds all your files that should be accessible from the outside.
This way nobody can access any other file in your application.
How do you remove the public in your URL? Well you don't "remove" it at all. Instead you should point your domain (virtual host) directly at public (this is called Document Root)
If you don't have the possibility to do that (usually because your on a shared hosting with very restricted permissions) then and only then you need to move files or use a workaround with .htaccess. However if your hoster doesn't allow you to set the document root I would consider to switch to another one...
By the way: This is not really unique to Laravel. A lot of PHP frameworks do it (Zend Framework, Symfony, etc) all have a dedicated directory for files that should be accessible - separated from the framework core and your application.
If you're having trouble setting up your development environment correctly, you should try out Laravel Homestead. It's a pre-configured Vagrant box that makes it very easy to get your site locally up and running (also comes without public in your URL!)
When you make your site's root point to the public folder, e.g. www.mysite.com points to /path/to/laravel/public, there are a few advantages.
Your files outside of public, like your .env with your passwords cannot be accessed doing things like www.mysite.com/../.env and other common "exploits" are prevented just by taking this simple approach.
It's quite a common pratice in other frameworks too, not only Laravel or PHP.
I need to confirm ownership of domain, as instruction says, place special .html file in main directory.
It confused me. Tutorial says, that file should be avaliable as www.domain.com/file.html
I placed it in views folder, but nothing. I wouldn't like to set special controller-action-route for that(it is quite weird), but looks like I should? Or other way?
How do I do that in terms of Rails app?
Just put file.html under the public folder, and visit www.domain.com/file.html
In Rails everything within the public folder is visible to the outside world.
I have the following folder structure in my zend framework 2 tutorial project in Ubuntu:
/zf2tutorial
/module
/Album
/view
/album
/album
myImage.png
index.phtml
in my index.phtml code I have a line such as this:
<img alt='SMALLIMG' src='myImage.png'/>
this does not work.
If I change the myImage.png to be http://www.someurlhere.com this works fine.
How do I load in myImage.png instead? I tried giving it the direct URL:
/home/myUsername/NetBeansProjects/zf2tutorial/module/Album/view/album/album/myImage.png
I've also tried doing the following:
../myImage.png
but neither of these worked.
Also please note, it has to be a bad path (I must be doing something wrong here) because the broken image icon shows up... indicating there is a linking problem here.. the direct URL is copy pasted from the properties section of the image itself..
It's not a problem of image or path. You are trying to make an impossible thing.
You certainly define in your virtualhost configuration that the documentRoot is your public directory.
That means your web server will give access to resources located from this public directory.
You have to put your resources from this public path (css, images..) or you can define a symbolic link if you allow followingSymlinks.
Hope this helps.
<img alt="" src="img/2 header960.png" align="center" >
The fundamental issue you are confusing is the difference between views vs public content.
View files are essentially HTML templates into which you can inject certain values at runtime. Your directory structure correctly places this stuff within a views directory inside your module. These template files themselves are never exposed to the end-user. They are only used by the application to generate fully-populated HTML chunks that are eventually sent to the browser.
In contrast, static assets - like images, javascripts, external stylesheets, etc - are served directly by the webserver to your visitors. As such they need to be in a directory that the webserver has been told to publicly serve to visitors.
The easy thing to do is to simply move directories containing these static assets out of the module and into the app's public folder.
But this is undesirable in the sense that you might reasonably want the module to be a self-contained entity: it can contain its own routes, its own controllers/actions, and, in particular, its own static assets.
So, how to make the webserver reach down into the module and treat some of the content there as "public"?
The answer is to use an "asset manager", a component that links certain module content into the app's public directory. Typically this means:
Activate the asset manager module
Create a public directory inside your module
Place those static assets there
Inform the asset manager which public module directories into the public app directory.
Take a look at the AssetManager module by Roberto Wesley Overdijk and additional instructions for use.
[As a side note, welcome to the world of web development. ZF2 is a great framework, but it's not the easiest thing for a beginner. It provides a lot of flexibility for doing things in a "good way", but it can certainly come off as convoluted at first. Try not to get discouraged. ;-)]
the reason may be the image extension (.png)
please check your exact extension case, is it written in small or capital case???
update your image link exactly as like the name of image.
eg.
myImage.png or myImage.PNG
try to look for an .htaccess file somewhere in your dir most probably on module folder..that file blocks the access for the image you are trying to link..(my basis here is my application in yii which fails to show the image even if the path is correct)
you may create an images folder in your home dir: /zf2tutorial/images for example and put all the images there calling it: src="/images/myImage.png"..
or
find the htaccess im talking about, change the restrictions(or delete it:|) and you can use this path: src="/module/Album/view/album/album/myImage.png"..
<div id='small_image'>
<a href='/feeds/posts/default' title='smallimg'>
<img alt='SMALLIMG' src='c:/home/myUsername/NetBeansProjects/zf2tutorial/module/Album/view/album/album/myImage.png'/>
</a>
</div>
I am wondering if there is a designated place for resource files in a Grails application? I have a csv file that gets loaded into a map (nothing major) but didn't quite know where to put it in the project.
So my question is, is there a dedicated place in the project to place this file? (If so, where?) Or is it better to place it outside of the project?
If the csv is going to need updating from time to time, I'd put it external to your grails folder, and point to it from config.groovy.
If it's basically a static file, I'd put it in src/java/resources, and load it with something like this.class.getResource("/resources/file.csv") as you would with a regular java app
I have an ASP.NET MVC2 application where I need to support not only multiple languages, but also potentially multiple versions of each language. I usually solve localization requirements by using resx files in the App_GlobalResources folder, and this works well as long as I do not need to support multiple resource-sets for the same language.
This is an issue because each customer shall be able to specify a set of resources, and they may use the same language.
My initial thought was to have a file structure where every customer has a separate folder located under for instance App_Data. In this customer folder I would put configuration files and resources. But then I would need a way to tell the application that it should look for resources in this particular folder instead of App_GlobalResources.
So my question is: Is this doable, and what do I have to do to make it work? Is this a bad way to solve a problem like this, and if that seems to be the case: Does anyone have suggestions for a better solution?
Will be thankful for all input.
I usually use a custom ResourceProviderFactory to store the resources in the database. Creating a custom provider to look in specific folders should not be to hard if you can distinguish the different customers by virtualpath.
But then I would need a way to tell the application that it should look for
resources in this particular folder instead of App_GlobalResources.
You might consider compiling your resources so that they are deployed as DLLs rather than compiled at runtime. To do this you have to move your resources our of the standard App_GlobalResources.
This post has a good explanation of the benefits of doing this:
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx