Hot answers tagged

5

You're probably looking for Element::getDirtyAttributes() and Element::getDirtyFields()! The former is for native class properties/attributes (and is based on an ActiveRecord pattern in Yii, I believe...), and the latter is for Craft's "fields," which may or may not be available, based on what type of Element you're looking at (and what FieldLayout ...


3

It's been a while since I was in Craft 2, but I'd suggest checking out this page in the docs: https://craftcms.com/docs/2.x/folder-structure.html Do all of the directories mentioned on that page exist on your site? Specifically, I'd confirm that you have the craft/storage folder created in your installation. If it's not there, make it and try to load the ...


2

I definitely would not recommend trying to install v2. Craft CMS 3 has many improvements over v2, a strong plugin ecosystem, and it will be supported for significantly longer. As for your setup issues, this is very likely some kind of a server config issue or Craft config issue. To find out which, we need to look at the error logs. First, look to see if ...


2

As per the docs at https://craftcms.com/docs/3.x/extend/element-types.html#saving-custom-field-values When saving values on a custom field, always use the setFieldValue() or setFieldValues() methods rather than directly accessing the field handle as a property on the element object. This ensures the value is normalized and marked as dirty for delta saves. $...


2

Your code is almost there, Craft allows registering routes for the Control Panel and the front-end of the site. You need to change EVENT_REGISTER_CP_URL_RULES to EVENT_REGISTER_SITE_URL_RULES. You are listening for an event on EVENT_REGISTER_CP_URL_RULES which will only register routes inside the control panel. This is useful for plugins that want to add ...


2

You need to register asset bundles in your plugin, see the Craft docs -> https://docs.craftcms.com/v3/extend/asset-bundles.html


2

Forgot to add the return keyword :( return $this->redirect('https://foobar.test');


2

The currentSite property from the Sites service is what you're looking for. Here's how you would use it: 'api/search.json' => function() { $siteHandle = Craft::$app->getSites()->currentSite->handle; ... $criteria = [ 'site' => $siteHandle, ... ]; return [ ... ]; },


2

You could add a new param to the request called skip and use that on your homepage, and default it to zero to allow you to reuse the endpoint elsewhere. $skipEntries = Craft::$app->request->getParam('skip') ?? 0; $criteria = [ 'section' => $settings['section'], 'limit' => $settings['limit'], 'offset' => ($settings['limit'] * ...


2

If you always want to skip the first 6 entries, you can modify the Element API endpoint to add 6 to the offset number in the query criteria: $criteria = [ 'section' => $settings['section'], 'limit' => $settings['limit'], 'offset' => ($settings['limit'] * Craft::$app->request->getParam('offset')) + 6, 'order' => $settings['...


2

The main issue is that the require_once CRAFT_VENDOR_PATH.'/autoload.php'; fails. This is because the DIR constant, used to compute the value of CRAFT_BASE_PATH and CRAFT_VENDOR_PATH is undefined. Try to define the value of the DIR constant so that CRAFT_VENDOR_PATH points to the vendor directory in your Craft project (it hard to help you further without ...


2

I assume that $block->tweet->one() returns an Asset element in your matrix block called tweet. I suggest that you use the getContents() method on Craft's Asset element type to retrieve the string content of the actual file. Your code block would look something like this: case 'tweet': $tweetFileContent = $block->tweet->one()->getContents(); ...


2

It's the __toString() magic method: The __toString() method allows a class to decide how it will react when it is treated like a string. https://www.php.net/manual/en/language.oop5.magic.php#object.tostring


2

Type php --ini in your server environment, it should tells you where the .ini files are getting loaded. Then set allow_url_fopen = 1


2

This worked just fine. https://craftcms.stackexchange.com/a/35846/10953 I did all steps execpt steps 3. and 4. Thanks all!


2

You can't access date this way, you'd need to use the date (docs) or datetime (docs) or even atom (docs) filters. In the case of your report, since you have multiple conditions, you would need to pass those as an array and use the atom filter. Try: {% set purchases = purchases .postDate([ 'and', '>=' ~ settings.datetimeStartDate|atom, ...


2

I've looked all over for a solution to this but couldn't find anything. I don't know if you've already fixed your problem now, but in case you haven't or someone else has found this error and arrived here, a simple fix for it is to add the missing information into the project.yaml in config/project/. For my local development build, I used the following: ...


2

This is how I would go about this (in a local or dev environment): PHP First, activate PHP 7.4 and check if the site still works as it should (frontend, backend). I don't know exactly if version 3.3.4.1 works with PHP 7.4, but it's easier to switch back to an older PHP-version than reverting a Craft upgrade. Craft After you've made sure that the site still ...


1

You need the url, not the file path. Can you store the url, or the http://localhost:8888 part of it in an environment variable? That gives you $url = getenv('CRAFT_URL') . $id . ".json"; If it is not already in an environment variable, then in a .env file? web/index.php that comes with Craft is a good example of loading a .env file, and then using ...


1

Where did you define your aliases? If you haven't already, you could start by adding directives for both php and composer in your .bash_profile. The file should contain something like (alter paths as appropriate): # Include the location of the PHP 7.4 binary in your path export PATH=/opt/plesk/php/7.4/bin:$PATH # Ensure that any calls to composer are run ...


1

Fixed it! The problem was that somehow, with that product, there was an issue with setting the status of the order to 'Paid'. Once I got that working, I saw the lineitems in my order.


1

Craft comes with a vendor directory were all your extras and plugins are stored, and the content of it is installed through the composer craft setup, as the contents is stored in your composer.json. I'd make sure you read this thoroughly: https://craftcms.com/docs/3.x/installation.html#step-1-download-craft You can also go to this url to install craft ...


1

You'll want to run that composer create-project command from inside of your Nitro VM. If you run it on your host machine, it'll use whatever version of PHP your host machine has installed. Do this: Make sure Composer is installed in the VM by running nitro install composer from the host machine. https://craftcms.com/docs/nitro/commands.html#install-composer ...


1

There's a plugin that allows you to connect to an external database, which will allow you to do a query within the template. Remember to cache the result though as it could slow things down otherwise. Another option is to sync the external data with Craft using feed me, so you can pull the data locally.


1

Open the php.ini file in your favorite text editor. Search for max_execution_time. It'll probably be set to something like 30 or 60. Change it to 120 and save the file. You'll likely need to restart your web server before the change takes affect.


1

You can't use entries from the control panel in other control panel fields without the use of a plugin. The only plugin I'm aware of that does this is https://plugins.craftcms.com/craft-dynamic-fields. Depending on the use-case, which I don't totally understand, you might look at using an Entries or a Categories field too if you just want to relate an entry ...


1

{% js %} let admin_email = "{{ admin_email }}"; console.log(admin_email); alert(admin_email); {% endjs %} Missed the "" around the assignment. :)


1

All the files that you've put in the HTML folder should be in a separate folder named "web" (/var/www/WebServerRoot/web - in your case). Move them from html folder to web and check if that solves things for you. If not, check these solutions: Check appropriate user permissions (ls -lh) for your webserver root folder. I had hit a wall with this thing for ...


1

In Craft almost everything is an element type (assets, categories, entries, global sets, matrix blocks, tags and users). If something is an element type you can attach arbitrary fields to it. Using fields like the Assets field, Entries field, Categories field or Users field you can define relations (link) between these elements. For fetching elements via an ...


1

With your plugin you can check for a front-end request, and if so inject an asset bundle public function init() { // Check if front end request $request = Craft::$app->getRequest(); if ( $this->isInstalled && !$request->isCpRequest && !$request->isConsoleRequest ) { $this->...


Only top voted, non community-wiki answers of a minimum length are eligible