CakePHP 2 path to webroot dir - cakephp

How to create $this->Html->link(); to download file from Plugin webroot directory?
It's possible?

Why do you have to put the file in Plugin folder to be downloaded. This is not a good practice. Keep the file in webroot/file/name_of_folder
to get the path to webroot/ simply:
debug(WEBROOT);

Prefix with the plugin name
As mentioned in the docs, you can download plugin assets if the request url is prefixed with the plugin name (lower cased and underscored):
Simply prepend /plugin_name/ to the beginning of a request for an asset within that plugin, and it will work as if the asset were in your application’s webroot.
Note however that if the file is intended to be public it's a better idea for the asset to actually be in the webroot:
But keep in mind that handling static assets, such as images, Javascript and CSS files of plugins, through the Dispatcher is incredibly inefficient. It is strongly recommended to symlink them for production. For example like this:
ln -s app/Plugin/YourPlugin/webroot app/webroot/your_plugin
This would make it possible to access all files in a plugin's webroot directly without any rewrite or php logic being involved.

Related

How can I keep all my static content under content?

I have images, PDFs, etc. that I would like to store in one location (/content/) instead of /static/ folder for organizational reasons. Obviously, Hugo should copy this to static when I serve the webpage.
How can I do this?
Hugo can't copy things in the content/ directory to static/ by itself - you would have to use a pre-processor or post-processor like Grunt or gulp.

Grails 3.0 static html in run-app

similar questions have been asked before, regarding grails 2(.3, .4). I find it strange that i could not find a way to do this, as it seems a standard use-case to me.
I simply want to serve html-pages, including their linked .css and .js (angular and jquery content) when i run grails run-app.
I want to check if my http-calls are handeled correctly on both sides - without needing to deploy a .war and configuring a database.
afaik grails run-app simply starts a jetty/tomcat - both of which can obviously serve .html pages. What do i have to do to make the grails development-tooling deploy my files?
I need to make http-requests,
so using a different Server would violate JS-SOP,
while deploying the .war would greatly slow down the development process
I've so far only found clunky jsonp, proxy, .war deployment solutions, or solutions for grails 2.x
I tried placing the files literally everywhere in the projects' structure (/src/main, /src/main/resources, /src/main/public, the assets folder and its subfolders, created web-app directories in every subdirectory, the Init, domain, conf directories - you name it)
Add the index.html to src/main/resources/public
Then add this to UrlMappings.groovy:
"/"(redirect:"/index.html")
For grails >= 3.0.12
Location of static resources
In order to resolve an issue around how POST requests are treated for
REST applications on non-existent resources, static resources located
in src/main/resources/public are now resolved under the /static/** URI
by default, instead of the base URI /**. If you wish to restore the
previous behaviour add the following configuration:
grails.resources.pattern = '/**'
https://github.com/grails/grails-core/releases/tag/v3.0.12
Contrary to the accepted answer, you don't need a redirect. I have made able to make this work with the following config:
UrlMappings.groovy
"/"(uri: "/index.html")
application.yml
grails:
resources:
pattern: '/**'
Finally, you just need to have your index.html file located under src/main/webapp

AngularJS 1.2 Not allowed to load local resource

I know it would be great if the file wouldn't link to local resource, but using phonegap/steroids framework, FILE_URI returns "file:///Users/" path which I can use for uploading to S3 or else, but Angular won't show it in the template.
Is there a possible solution? I tried adding config to my app
.config(function ($compileProvider){
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
})
but it seems that doesn't have impact on the error.
I can base64 encode my images (then works), but I would like to avoid this if possible.
thanks
See the Camera example in the Steroids Kitchensink app, where the Cordova File API is used to move the picture from the tmp folder to the Steroids app's User Files folder. Since Steroids's localhost looks for assets both in the App folder and User Files folder, you can use an absolute path, e.g. src="/my_image.png". See also the App Structure on Device guide for more information on the App and User Files folder.

Configuration of Solr Request Handlers in Tomcat

I a complete noob at solr/java . I have solr 3.6.1 running on Tomcat(Windows) . I am able to get the solr admin page . I want to move ahead with DIH configuration . However the solarconfig.xml is confusing specially the paths for the class of request handlers. The request handler classes are specified as
"solr.SearchHandler" or as "org.apache.solr.handler.dataimport.DataImportHandler"
I cannot find either of these files either in my solr home directory or solr webapp (under the tomcat webapps folder) . I did find HTML files for these in my solr download (which is placed separately since I just copied the example/solr directory for solr_home and solr.war file for webapp) . Do I need to manually copy these files and if so where and how should my directory structure look like ?
solr.SearchHandler class is resolved by the Solr war file. For org.apache.solr.handler.dataimport.DataImportHandler class you should add the required jar file into the lib directory. Final solr directory should look like :
-solr
+conf
+data
-lib
+apache-solr-dataimporthandler-x.y.z.jar
+apache-solr-dataimporthandler-extras-x.y.z.jar
+apache-solr-x.y.z.war
+solr.xml
Also you should add other needed libraries inside the lib folder.
For DIH, you need to add the respective jar (apache-solr-dataimporthandler-x.jar) to the lib directory in webapps (Tomcat). Also copy the files in contrib/dataimporthandler/lib to this directory.
Every class files need for the DIH is inculded in the war file which comes with the web app folder. You can use these for your out of box functionalities. If you really want to work around the code for any customization then you can download the release with source code in the repositary.

all css files and image are not loading in cakephp

Why all css files and images are not getting loaded in cakephp. Although i've written code like this in my default.ctp
echo $html->css('generic');
Please help me in this issue..
css files are placed in app\webroot\css
You have to copy the .htaccess file into your htdocs/yourcakeproject/ directory.
If you're running your Cake application on an Apache webserver you have to make sure that the module mod_rewrite is installed.
If you use Lighttpd as your webserver, there is a chapter in the CakeBook how you have to configure Lighttpd: Pretty-URLs-and-Lighttpd.
Try this changes.In Apache config File
1.LoadModule rewrite_module modules/mod_rewrite.so
(Enable This Line) by removing #.Next Step is
2.Replace This Code “AllowOverride None” By “AllowOverride All”.

Resources