My team uses a custom NuGet package for installing jQuery UI, which puts the theme files into a directory structure like this:
Content
jquery-ui-1.10.3
images
jquery-ui.css
jquery-ui.min.css
I'm trying to use ASP.NET MVC 4 bundles to include this content in the BundleConfig class inside my application's App_Start folder like so:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css",
"~/Content/jquery-ui-{version}/jquery-ui.css",
"~/Content/Site.css" ) );
This throws an error when I run the site:
Directory does not exist.
Parameter name: directoryVirtualPath
I also tried:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css" )
.IncludeDirectory( "~/Content/jquery-ui-*", "*.css" )
.Include( "~/Content/Site.css" ) );
That doesn't work either (obviously). I can explicitly specify the version on the folder, but that defeats part of the benefit of using the bundle.
So how can I use a wildcard in the folder path?
You could use the overloaded version of IncludeDirectory which searches subdirectories.
Suppose you have the following file:
\Root\Content\jquery-ui-1.10.3\jquery-ui.css
Use this code to find and add it:
.IncludeDirectory("~/Content", "jquery-ui.css", true)
This is useful because it will always find jquery-ui.css, regardless of where you put it.
The downside to this method is that it will search for and include all jquery-ui.css files that it finds, which could cause some bugs if you don't ensure that only one jquery-ui.css exists.
(Remember that searching for subdirectories will also still search the root directory i.e. ~/Content)
Related
Is there any way to set default Contents location in different path or using different name instead of Contents?
Edit:
Thus, I can download bootstrap or something else from nuget which are related with Content folder into the new directory.
You can use whatever name you like. Just rename the folder and update your BundleConfig to reflect the new name:
bundles.Add(new StyleBundle("~/SomeOtherName/css").Include(
"~/SomeOtherName/bootstrap.css",
"~/SomeOtherName/site.css"));
And in the _Layout.cshtml make sure to include the correct name:
#Styles.Render("~/SomeOtherName/css")
in my Grails project I'm using elfinder plugin to manage files and directories. I want to have a dynamic root directory, because I use the plugin for different folders.
The path of directory is like the following:
grails.plugin.elfinder.rootDir = "${userHome}/docm_patients_doc/{patientcf}/"
where patientcf is the id of an entity in my application. When I enter into the show.gsp page of that entity, I need to replace the patientcf with the related value.
How can I do it?
EDIT:
I've tried to modify the placeholder before the script and div that shows elfinder in gsp page, but I notice that the path is not modified. Maybe the gsp is not the place in which the placeholder can be modified...
I am author of elfinder plugin, though plugins isn't developed with multiple roots in mind.
You can try this. Plugin registers a spring bean with name elfinderFileManager which has a property with name ‘root’ which is path to your root directory. Try setting the root property at runtime. The bean can be injected in your controller/service and you can try changing the root property.
How do I get application's root directory within an action?
The first thing ZF2 does is to change the current dir via chdir(dirname(__DIR__));
This means that every future include is based off of the ROOT PATH of your application and NOT the public folder. Or any other current folder.
Of course this only holds true for PHP-Files.
If you want to define the root path manually, you'd go to /public/index.php and add a line like define('ROOT_PATH', dirname(__DIR__));
As i said before, for INCLUDES this is NOT required though ;) as you're ALWAYS in the root folder when it comes to PHP-Files ;)
getcwd() works best for me, DIR return the module root. Which isn't much use in this case
#Sam:
I don't really understand your question. Basically the current path equals the ZF2-Apps Root. [...] You can always go up-levels, too via ../
Not exactly. When You create module shared within several applications ex. FileUpload Module in vendor, outside application. You would like to upload file to Application subdirectory not shared module :) In this case __DIR__ equals module path not app path and ../ wouldn,t be good solution ;)
I like ROOT_PATH as You have mentioned:
define('ROOT_PATH', dirname(__DIR__));
or even better:
getcwd()
so, I have some php files in my apps/myprogram/lib folder. e.g. apps/myprogram/lib/myLibA.class.php
When I run in my modules/actions/ scripts, and try to use the functions in myLibA, I cannot. because symfony complains that the myLibA class is not defined.
do I need to specify anywhere in the symfony framework that myLibA.class.php is a required library?
Symfony's autoloader looks by default for your classes in the top-level <project>/lib directory. Any file in that directory or below (with the exception of "vendor") will be searched for classes. Symfony searches for any .php file with class declarations and adds them to the autoload system.
Additionally, you can add search paths in your application's autoload.yml file. For example, for one of my applications I've put a third-party Flickr library in <project>/vendor/phpFlickr, and my <project>/apps/frontend/config/autoload.yml file looks like:
autoload:
vendor_php_flickr:
path: %SF_LIB_DIR%/vendor/phpFlickr
recursive: on
That allows all classes below .../vendor/phpFlickr to be autoloaded.
this is an alternative way, you can define/add to your preExecute this:
public function preExecute()
{
$this->getContext()->getConfiguration()->loadHelpers('Foo', 'Bar');
}
taken from (http://oldforum.symfony-project.org/index.php/m/92916/)
I have a mvc project and in the bin folder i have an plugin folder and it look like this
/bin/
/plugin
/plugin1
/plugin2
and i what to scan with structure map every assembly in plugin folder
i've try with AssembliesFromPath but is not loading any assembly.
How can i load all the assembly from every directory within plugin folder ?
StructureMap doesn't recursively search a path, so you just need to call AssembliesFromPath on each of the paths that contain your plugins (ex: bin\plugin\plugin1, bin\plugin\plugin2).
Of course you don't need to hardcode in all of the subdirectories. StructureMap registration code is c#, which means you can use the language constructs. Call Directory.GetDirectories() on your bin\plugin to get the list of subdirectories, and then just loop over them within your Scan() clause to call AssembliesFromPath on each subdirectory.