26
votes
Accepted
What's the recommended way to include vendor library dependencies in your plugins?
Composer!
There's already a package for Stripe: https://packagist.org/packages/stripe/stripe-php
Install composer.
Add a composer.json file in your plugin's root folder.
Add this to the composer....
19
votes
Accepted
grab 'environmentVariables' with a tag
You can get to any of your config variables (including custom ones) like this:
{{ craft.config.xyz }}
The environmentVariables array is no different:
{{ craft.config.environmentVariables.baseUrl }}
...
14
votes
When uploading assets what determines the maximum file size?
Craft itself, limits the filesize only in the maxUploadFileSize. Default: 16MB
However Craft gets limited by:
PHP: Has a few values which might cause the problem:
memory_limit
max_input_time
...
13
votes
How can I check from a plugin config file if devMode is enabled?
For those coming here using Craft 3, it's now Craft::$app->getConfig()->general->devMode.
12
votes
Accepted
Bootstrap Craft from another app
Craft’s bootstrap file in located at craft/app/index.php. Importing that will get you 99% of the way there.
The only problem is, index.php not only loads Craft, it also runs it. In doing so, Craft is ...
12
votes
Accepted
Can I run one Craft install on multiple domains and/or subdomains?
Update for Craft 3
Craft 3 includes native support for multi-site installation. Here's a link to the official docs and here's a link to another question with more resources.
Old answer for Craft 1 &...
12
votes
How can I use multi-environment configuration to set each root URL?
Make sure to change the "Site URL" setting to {siteUrl} in your control panel settings...
Control Panel > Settings > General > "Site URL"
Within your config file, you'll also want to put your ...
12
votes
How to set up {siteUrl} to work with both http and https
One method is using something like the following in your general.php file. Using this method the config settings will take on the scheme of the request being made. I've set both the siteUrl and ...
11
votes
When uploading assets what determines the maximum file size?
It's almost always an environmental limitation. The most common culprits are:
1) PHP's memory_limit setting: http://us3.php.net/manual/en/ini.core.php#ini.memory-limit
2) PHP's post_max_size: http:/...
11
votes
How do you set up Craft CMS to back up your site automatically?
Options:
1) Craft will automatically run a backup of the database anytime an update is performed and save it to craft/storage/backups
2) You can manually create a database backup by going to ...
11
votes
Accepted
Getting environmental variable via plugin
Solution:
return craft()->config->get('environmentVariables')['baseUrl'];
10
votes
Accepted
Cannot connect to database with credentials provided in db.php
Move the check the SERVER_NAME switch up above the require_once $path;. You need to set CRAFT_ENVIRONMENT earlier.
10
votes
Can I run one Craft install on multiple domains and/or subdomains?
Yes, it is possible to have a Craft install on multiple domains and subdomains as long as you only access the control panel from a single domain and you only have a single installation of craft that ...
10
votes
Accepted
Custom template location
The default template path can be changed by setting the CRAFT_TEMPLATES_PATH PHP constant in your index.php file:
define('CRAFT_TEMPLATES_PATH', "path/to/templates");
I would recommend, however, ...
9
votes
Accepted
Is Redactor's default config saved as a .json file anywhere?
As @Brandon said, the defaults are hardcoded in redactor.js so there isn't a default.json file, but if there was, this is what it would be (from Craft 2.3.2615):
{
buttons: ['html', 'formatting', ...
9
votes
Accepted
`routes.php` config example
The simplest way to transform dynamic routes into advanced routes, is to go to your craft_routes table and copy it out of urlPattern:
Example:
If you have set this in your backend:
news-sort/month/&...
9
votes
URL rewrite not working
I solved the problem and am writing it down for future people encountering the same problem.
Add the following configuration to the your craft/config/general.php config file:
'omitScriptNameInUrls' =...
9
votes
Accepted
Do I need the web.config file in the craft root directory?
If you're not specifically running IIS on Windows, then you can safely remove it.
9
votes
Accepted
HTML Purifier Config File
Something like this in a .json file should work:
{
"HTML.SafeIframe": true,
"URI.SafeIframeRegexp": "%^(https?:)?//(www\\.youtube(?:-nocookie)?\\.com/embed/)%",
&...
8
votes
Mcrypt is required on Ubuntu 14.04
I had to run sudo php5enmod mcrypt to enable the module.
It seems this has changed between 12.04 and 14.04—in 12.04 it was enabled automatically.
8
votes
Accepted
When uploading assets what determines the maximum file size?
It's most likely PHP. Most PHP installations come standard with a 2M limit.
Check out this Stack Overflow thread for more information on what needs to be adjusted.
8
votes
Accepted
Can I change the list of available locales?
You can download the locales you want from https://github.com/yiisoft/yii/tree/master/framework/i18n/data and place in your craft/app/framework/i18n/data folder and they will show up as options.
...
8
votes
Accepted
How can I set dynamic absolute Asset URLs?
If you want to use the {siteUrl} tag in your Asset source settings, you'll still additionally need to define it in your environment variables as well.
See here as well.
8
votes
Accepted
CSS is not loading on staging server
There are multiple ways to set the URLs to your files. I don't know if I got your folder structure right. But let's suppose that your web root is set to
/var/www/craft-portfolio/public/,
your CSS ...
8
votes
Accepted
Query table in a different database
Have you tried it? I'm pretty sure that's not going to work as Active Record is tied to the db connection in craft/config/db.php hanging off of craft()->db.
You should be able to pull it off with ...
8
votes
Accepted
How can I check from a plugin config file if devMode is enabled?
It's as simple as
if ( craft()->config->get( 'devMode' ) )
{
//do stuff
}
8
votes
Accepted
Craft 3: how can I set dynamic Base URL in sites setting?
So as of Craft CMS 3 RC7, they added a new alias() Twig function.
So what you can do is something like this in your general.php:
'aliases' => [
'@basePath' => getenv('CRAFTENV_BASE_PATH'),
...
7
votes
Accepted
Are there any intentions to release multisite support for Craft?
Currently multi-site support isn't planned.
If you want simple multi-site-support you could use the localization feature with a custom locale. But with Craft's auto-update's and easy deployment, why ...
7
votes
Accepted
Environment Variable siteURL ignored
In your Control Panel, go to Settings > General.
Then set your Site URL to {siteUrl}.
This will parse out the siteUrl environment variable. For more information, see this thread...
7
votes
Accepted
omitScriptNameInUrls is not working
On recent Ubuntu systems (for sure on 14.04), mod_rewrite is installed but not enabled within Apache. You may just need to enable the rewrite module and restart Apache.
$ sudo a2enmod rewrite
$ sudo ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
config × 249craft3 × 24
multi-environment × 24
database × 17
url × 17
assets × 14
templating × 13
users × 12
configuration × 12
plugin-development × 11
control-panel × 11
localization × 11
php × 11
install × 10
siteurl × 10
server × 8
environmentvariables × 8
session × 7
cache × 6
emails × 6
multi-site × 6
error-message × 5
password × 5
redactor × 4
error × 4