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()
Related
$link= PS_ADMIN_DIR;
$admin_folder = substr(strrchr($link, "\ "), 1);
currently i am using this way to get folder name,
But if there are any direct method or any constant please suggest me..
Thanks
To be a little bit more specific : the name of the admin directory is on the filesystem.
When you access a page of the admin directory, a script puts the current directory's path in the _PS_ADMIN_DIR_ constant.
If you forgot the name of the the admin directory you must have a look at the filesystem of your server.
Admin directories are automatically renamed to something like adminXXXX.
If you named it differently you can compare the default directory structure with your actual structure and find the proper directory.
You can also look for files that are only present in the admin directory. The "get-file-admin.php" file for example.
On linux, the following command run from the prestashop root directory will tell you the actual name of the admin directory :
find ./ -name get-file-admin.php
For security reasons, admin folder name is not stored anywhere in your PrestaShop's files or database, so you have to do something like you do to find it.
However, you should use _PS_ADMIN_DIR_ instead of PS_ADMIN_DIR as the second one is not defined directly by PrestaShop and could be undefined.
I'm working on prestashop and I'm Trying to override "order detail page" in front (customer's details orders).
This is how I did :
I copied file \controllers\front\OrderDetailController.php into folder \override\controllers\front\OrderDetailController.php
I copied also default template file order-detail.tpl into folder override/customtemplate/order-detail.tpl
And In OrderDetailController.php I have specified template directory like that
$this->setTemplate(_PS_OVERRIDE_DIR_ . '/themes/parfum_evo/order-detail.tpl');
I tried, it works fine except translations. Even watching the documentation, no test solution seems to work.
Could anyone help me? Thank you in advance :'(
The php override sits in the correct place. As for the other, you specified the path the override/customtemplate/order-detail.tpl but then placed it in override/themes/parfum_evo/order-detail.tpl. I take it as customtemplate is farfum_evo really, but you need to add another one named themes, after override, using that structure. I think. Because there is a hook named
DisplayOverrideTemplate
Which should take care of this, while I believe setTemplate for controllers will always grab from the main theme folder
I have some config file,they don't need use in everywhere,so i don't want it autoload,can you tell me how to load config file in controller and it can be get in serviceLocator,don't tell me to use zend\config\config, thanks。
First off, it's not advised to ask a question and then directly say that you don't want someone to tell you about XY. What if XY would be the only way?
You could always do something like
$onlyNowConfig = require_once('./config/onlyNowConfig.php');
The current working directory of PHP is the root of your application, as it's set in your public/index.php via the chdir() function.
Other than that, there's no real harm to include the configuration inside your module.config.php. The ModuleManager will check for the existance of the getConfig() function inside your Module class. If it's existant, the Configuration will be loaded. Typically every module has a config that will be loaded. And there's no real speed (dis)advantage of outsourcing 100-200 configuration lines into a separate file. The additional I/O you'd do by only including it on those few actions you need it would actually be higher than the very little time it takes longer to merge the configuration (probably like 1ms total vs. 2-3ms I/O).
I'd advise to just include it in your module.config.php and you'd have it available everywhere via the ServiceLocator, otherwise just include/require the one config file that you need, wherever you are. The include/require parameter would never change, as the working directory of PHP will not change, no matter in what file you are (as long as you don't set it anew via chdir() - which would be highly not recommended).
I make a call just like this:
value = ./simulated_annealing
Which is a C Object file, but Rails tells me it cannot find that file. I
put it in the same dir that the rest of the models files (since it's
called by one of those models), but I guess it should be in any other
place.
I've tried that outside Ruby and it works great.
What do I have to do?
The thing is, when you say:
./simulated_annealing
you're explicitly saying: run file named simulated_annealing which is found in the current directory. That's what the ./ means. If the file's located elsewhere you need to provide the path to it, or add that path to the environment variable $PATH. So, you should replace that line with:
/path/to/simulated_annealing
where /path/to represents the actual path.
The best option is to use an absolute path for running the program. For ex.,
you can create a directory "bin" under your rails application top level
directory. Place your program under "bin" directory. Then you can
execute the program something like:
cmd = "#{RAILS_ROOT}/bin/cbin arg1 arg2"
value = `#{cmd}`
Is there a variable where I can find out the root directory of my Grails application?
for example, I have a folder named chart under \%root%\web-app\images\ where I put my charts in. Once I deploy my Grails application on Jetty, I will get FileNotFoundException because the root path becomes /srv/www/vhosts/domain-name/jetty-version/
I would like to know if there is a variable that returns the root path (like /srv/www/vhosts/domain-name/jetty-version/webapps/myapp), and there should be because CSS uses relative path just fine.
solved.
request.getSession().getServletContext().getRealPath("/")
this actually gives me the path to where my application puts the images, css, WEB-INF, etc. folders.
System.properties['base.dir']
I know it is an old question, but this could work if you are not in an http request:
ServletContextHolder.servletContext.getRealPath('/')
If you want to establish this is GSPs try this:
${createLink(uri: '/')}