where should I declare Global variable in sugarcrm - global-variables

where should I declare a Global variable in sugarcrm so that I can access it from anywhere in sugarcrm application? Should I declare it in index.php or config.php or any other place?

config_override.php is the best location for custom config values. This file is placed in the root folder.
Set new value with:
$sugar_config['my_variable']
Retrieve value with:
$GLOBALS['sugar_config']['my_variable']

Related

Next.js dynamic route template

I want to create a dynamic route structure for my next.js project, so the main directory would be countries and there will be many other countries under that directory.
www.mysite.com/countries
www.mysite.com/countries/united-states
www.mysite.com/countries/france
www.mysite.com/countries/united-kingdom
....
In my pages folder, I create a folder called countries and created a file [...slug].js. I have to create a file index.js inside the countries folder for www.mysite.com/countries to be accessible.
The issue is that index.js and [...slug].js have the same code, and I want to have only 1 file to maintain. How can I configure nextjs to use [...slug].js for www.mysite.com/countries and any sub pages under it?
You can simply change [...slug].js to [[...slug]].js to catch all routes starting with countries. It is treated as optional URL parameters in NextJs.
Official NextJs documentation also said that:
Catch all routes can be made optional by including the parameter in double brackets

How to find /mysite/ folder - SilverStripe CMS

I'm having some trouble finding my /mysite/ folder - I'm trying to edit my _config.php file so I can add some schema to a website however, there is no /mysite/ folder. Is it possible it was renamed something else, or simply doesn't exist? Is there a way I can find out which folder is the "/mysite/" folder?
The global variable $project is defined with the name of the "mysite" folder (it's basically the project folder).
So echoing that out from ContentController::init() would be a good way to determine it. Otherwise, just search the folders for "Page_Controller" and you should find the page class and where all the other work is stored.
global $project;
var_dump($project);
die;
It should be in your webroot, where also a /framework/ and a /cms/ folder should be. Look at the webserver configuration to find out where the root of your website is located.
How did you install silverstripe? Did you use composer? Did you download a ready-to-use zip? If yes, which one?

Managing folder locations when swapping domains

I have recently been working an application that will soon need to be moved from one server to another. (Testing environment to live environment). The problem I am having is how can I make it so when I move folders, it will still work without need needing to change directories.
Example -
<?php include $_SERVER['DOCUMENT_ROOT'] . '/arcade/layouts/_header.php'; ?>
Here I include a layout file called '_header.php', the problem I will have when I move the test environment to the live is that we will need have the folder '/arcade' so this will be looking for a folder that doesn't exist. I could use ../ or ./ but then I couldn't be able to use $_SERVER['DOCUMENT_ROOT'].
My initial thought was to have a _config.php and in it have global variables such as
$root = "/arcade";
Then when I move from the test to the live I just have to change 1 value from "/arcade" to "" and possibly the directory to the config file.
Just looking for some insight for managing folders and files across domains
Having a configuration file is desirable anyway. Anything that is a parameter of the application (locations, access parameters etc, feature toggles, other flags etc.) should be defined there.
What is even better if you have a local configuration as well. In the configuration you can check if a local configuration exists (say config.local.php) and include it if it does at the end. This way you can have a minimal, possibly unversioned, environment specific override for settings that you need.

Get application root URL and Directory name in Symfony 2 application

I want to know the root of the application both system eg. /var/www/app/ or /app/ for the purposes of file uploads. When I upload, I believe I need the "system" directory name, for use to links in web front end, I need the "relative" path. How do I get this information?
In a previous project, I defined constants in the app*.php files (front controller)
define('APP_ROOT', __DIR__);
Wonder if theres a better way?
In any ContainerAware class you can get location of web directory by,
$this->container->get('kernel')->getRootdir().'/../web';
If the container is not available, you can use dependency injection: set %kernel.root_dir% as an argument to your class in the service configuration.

Umbraco - Get Directory of Config Files

I'm working with Umbraco 4.7.1 and I've created some extensions that hook into Document.AfterPublish and Document.AfterUnPublish. I need to find the directory of the config files from here, but need to be independent of server installation (i.e. a literal won't work). Is there any way of finding this at that point in time?
I think what you are looking for is the umbraco.IO.SystemDirectories class, specifically the Config property.
This will return "~/config" by default, but can be overridden by adding a umbracoConfigDirectory key to the appSettings section of the web.config file and specifying a different path there.

Resources