Questions tagged [php]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
1 answer
466 views

Is there a way to compare what has changed on an entry while it's being saved?

I'm taking my first baby steps into the php side of Craft, and my php experience in general is extremely fledgling. But I'm pretty much forced to create a module for a project I have, so here I am ...
Brimby's user avatar
  • 343
1 vote
1 answer
361 views

Get a key value from a JSON asset in PHP

I'm using the Apple News plugin to try and display a tweet that's been added as a JSON asset in a matrix field. The JSON looks something like this { "title": "https://twitter.com/...
Bryce's user avatar
  • 251
1 vote
1 answer
16 views

How do entry elements render a default string but also return an object at the same time?

So this is more of a PHP question than a Craft question, but the only example I can offer is one I've seen in Craft. {{ craft.entries.id(4).one() }} Returns a simple string like: "About Page"...
Mark Notton's user avatar
  • 2,337
1 vote
1 answer
101 views

Why does Bootup.php run with PHP 5.4.16 from with Craft script but PHP 7.4.10 from the terminal command line?

This is a problem encountered apparently by a lot of users when installing from the Craft setup/install files from the Craft web site. PHP Warning: Unsupported declare 'strict_types' in /var/craft/...
it's a hire car baby's user avatar
1 vote
1 answer
57 views

LineItems not showing in CMS

I'm scratching my head. My orders are shown perfectly except for one product. I have no idea why so I looked at the Order object before saving and I can't seem to figure out why he won't show the ...
Kap1tein's user avatar
1 vote
2 answers
847 views

Site moved to new server - Error 500

I inherited a site running craft and I was asked to move it to my server to host it. The other developer zipped the files and made a database dump for me. Usually, when I move a site, they have Cpanel ...
xecutech's user avatar
2 votes
1 answer
439 views

Craft Nitro PHP extension ext-zip * is missing

I'm not particularly tech minded so MAMP has served me well for a good while. However I more recently decided to give Craft Nitro a try. I got everything (Multipass and Nitro) set up really easy. I ...
Martin's user avatar
  • 1,203
0 votes
0 answers
132 views

Website Stuck on Load after few requests

I'm facing a weird issue here. I'm developing a CraftCMS based website and all seem to be working fine, until after a few requests (clicking around 4 ~ 5 requests) the website seem to keep loading and ...
TechMafioso's user avatar
1 vote
1 answer
115 views

Updates always error out

Every time I try to run an update, I get these errors. Installing plugins won't work either. I'm using Media Temple / Grid server hosting. I've increased the file size limits in php.ini as well. But I'...
Noah Yamen's user avatar
1 vote
1 answer
108 views

Put SEO and Twitter card Meta tags in the Head section prior the render of the template

I need to put some <meta /> tags in the <head /> section of the html document prior the rendering of the template. I would like to know how can I achieve this? I also need to query an ...
Rafael Mora's user avatar
1 vote
1 answer
148 views

Error when trying to update Craft

I'm pretty new to CraftCMS and am trying to install updates for a client. I am getting this error and I don't really know what it means. Any help of brief explanation for this would be appreciated. ...
patricko's user avatar
  • 113
1 vote
1 answer
5k views

The requested URL was not found on this server. Apache/2.4.18 (Ubuntu) Server at localhost Port 80

The frontend just work fine. But when I call the backend http://localhost/craft3/web/admin/dashboard/ or http://localhost/craft3/web/admin/ I get the error requested URL was not found on this server. ...
Luky's user avatar
  • 31
1 vote
1 answer
35 views

Setting relative path to ElementAPI in PHP

I need a few small bits of data from Craft in a PHP file. It’s a really small task, so I don’t want to delve into writing plugins or anything hardcore. It seemed to me the simplest way to approach it ...
mitrol's user avatar
  • 262
2 votes
1 answer
296 views

Get currentSite.handle in Element API

I need to get the currentSite in Element API. How can this be achieved? Is it as a slug in the endpoint URL? or as a Query param? Here is the current code: <?php use craft\elements\Entry; use ...
nfq's user avatar
  • 23
0 votes
0 answers
197 views

How to load more entries of a category on that category's page with Element API?

Following up on previous questions of mine: How to use multiple different instances Element API "Load More" button? I have a website that utilizes the "load More" (button) method ...
Justin Kendall's user avatar
1 vote
1 answer
125 views

How to use multiple different instances Element API "Load More" button?

Following up on a previous question of mine: How to skip the first few entries in a "load more" scenario with Element API? I have a website that utilizes the "load More" (button) ...
Justin Kendall's user avatar
1 vote
1 answer
149 views

How to skip the first few entries in a "load more" scenario with Element API?

I have a website that uses a "load more" button. The process for this button can be found here: http://craftsnippets.com/articles/infinite-scrolling-and-lazy-loading-with-craft-cms I made it ...
Justin Kendall's user avatar
1 vote
1 answer
400 views

Change php.ini to max execution 120

I found the php.ini file, but I don't see where to change max execution to 120. Thank you for your support.
Bren Bauer's user avatar
1 vote
2 answers
110 views

How to use entry data?

My question: How can I use entry data in the craft backend? An example for the use-case: Author creates an entry for the section "Generate item". The entry has only a title/single word. ...
Ichigo's user avatar
  • 21
1 vote
1 answer
169 views

How to auto enable a plugin after install?

I am developing a plugin for craft 3 and the plugin just got published to the store. I can browse through the store and install the plugin but it stays disabled. The user will have to goto Settings -&...
Rohan's user avatar
  • 217
1 vote
1 answer
205 views

Controller redirect not working in craft 3

I am working with Craft 3 and in my controller, I am trying to do this $this->redirect('https://foobar.test'); But it is throwing me back to the root url of my craft site. I am confused, what else ...
Rohan's user avatar
  • 217
1 vote
1 answer
72 views

How to get my craft projectConfig settings inside JS on the front end

So I am trying to work with twig templates and I want to inject my project configuration in my js so I can use it. I can do this {% set admin_email = craft.app.projectConfig.get.email.fromEmail %} ...
Rohan's user avatar
  • 217
1 vote
1 answer
938 views

Register custom REST routes while building a plugin for Craft 3

I am building a custom plugin for Craft and I am hitting some REST APIs in my backend service to fetch some data using Ajax calls in JS. What I would like to do when the AJAX calls complete and come ...
Rohan's user avatar
  • 217
1 vote
1 answer
600 views

Work with data/content from entries

I'm usually working on Backends with PHP and ZF/Laminas. Now I'm building a headless (only Backend) Craft CMS website and have a couple of questions that I didn't find a clear answer on. The Craft ...
Ichigo's user avatar
  • 21
1 vote
3 answers
247 views

How to add content to pages using a plugin?

I am developing a plugin for Craft 3. And I am trying to add some content to all pages in the CMS using this plugin. How can I do that? Is there a method or class call I can use for this? I am not ...
Rohan's user avatar
  • 217
1 vote
1 answer
450 views

Images not showing even after bundling them with asset bundle

So I am trying to build a simple plugin for Craft CMS and I am wish to use my assets in the twig template like css, js, images etc. From what I have read and understood from Asset Bundles, I have ...
Rohan's user avatar
  • 217
1 vote
1 answer
302 views

How to use assets while building Craft CMS plugins?

I am trying to build a basic plugin, when installed has a single nav bar item, and of course a twig template which shows up on clicking on that navbar item. I have used the basic template to extend ...
Rohan's user avatar
  • 217
0 votes
0 answers
138 views

Date Field Validation by PHP plugin

I have a form for updating user info, with a field of birth date. However, I am struggling to develop a validation for this date field by PHP. Its frontend code is this; {% set tz = craft.app....
Kota.M's user avatar
  • 423
1 vote
3 answers
142 views

Craft v3 gives 500 error on installation... how to get v2 instead

I installed Craft v3 on a live server running Debian 10, apache, latest PHP, and Mariadb. My structure is /var/www/html, and everything except for the files in "web" are in the www folder (along with ...
Elim's user avatar
  • 11
1 vote
2 answers
103 views

How to call abstract method from interface

I would like to use a method of fileExists. It belongs to VolumeInterface. https://docs.craftcms.com/api/v3/craft-base-volumeinterface.html I suppose the code would be like \craft\base\Volume::...
Kota.M's user avatar
  • 423
1 vote
1 answer
34 views

How to exclude multiple email addresses from an order query

When doing an order query I want to omit results for 2 particular email addresses. It's easy enough to omit results for one address; $order = Order::find() ->isCompleted(true) ->email('...
foamcow's user avatar
  • 2,019
2 votes
2 answers
466 views

Is it possible to allow logging at LEVEL_INFO without logging all the SQL queries?

We're currently logging our site at LEVEL_INFO to have a good idea of what's happening on the site. We find it useful, and appropriate, to log informational messages at that level rather than at ERROR ...
Aaron Cimolini's user avatar
1 vote
1 answer
92 views

Click counter for links (craft v2)

So I'm new to PHP and ok with Javascript. I have a page on my site with a long list of external links, would it be possible to add a counter to be displayed next to each link that shows how many times ...
Stephenio's user avatar
1 vote
3 answers
2k views

Programmatically add entries to an Entry field (craft\fields\Entries)

I work with Craft 3. I have an Entries field in a global set, I am able to get the global set, and then "read" this field programmatically (in a plugin) to fetch the entries that where added to it by ...
Gfra54's user avatar
  • 113
2 votes
1 answer
159 views

How can I write a PHP script to zip and download an Assets subfolder?

I've searched everywhere but can't seem to get a straight answer. I want to write a php script to zip and download an entire subfolder in my assets directory. The subfolders are named based on a ...
JJefferyDev's user avatar
2 votes
1 answer
1k views

Undefined index: siteSettings when updating entry types

I'm receiving an Undefined index: siteSettings when trying to save changes to entry types (both new and existing). Of course, this is only occurring on a production server - local server with up-to-...
raptureaid's user avatar
2 votes
2 answers
4k views

ext-zip trouble

Issue: craftcms/cms 3.3.9 requires ext-zip * -> the requested PHP extension zip is missing from your system. Details: I am running on MAMP Pro 5.3. Currently using PHP 7.3.3 (but previous versions ...
Seraphim Jester's user avatar
2 votes
1 answer
352 views

How does the Craft CMS built-in web server works?

I just found this while using ./craft help in the Craft CMS command line utilities: - serve Runs the PHP built-in web server. serve/index (default) ...
Romain P.'s user avatar
  • 1,818
3 votes
2 answers
1k views

Craft 3 plugin - how to update entry with field of Entries type

Using PHP, I want to update a field of Entries type of an existing entry. Fields of type Text and Number will update with the following code: $entry = Entry::find()->id($entryId)->one(); $...
biko's user avatar
  • 670
2 votes
0 answers
299 views

How to wire html template to twig extension? (Mainly `Twig\Error\SyntaxError: Unknown filter Error`)

I am going to use a Twig filter function by using Twig extension in my HTML file. I followed this guide. https://cameronspear.com/craft-cms-twig-filter-extension/ But when I run <p>{{ 123 | ...
apollo's user avatar
  • 63
1 vote
2 answers
143 views

How to build a web page using different sections created in Craft

I am a beginner in Craft. I have a Craft website. There is an HTML design with me. From admin, I divided the HTML into sections and created entries based on that. All the coding related to each ...
Rakhi Vijayan's user avatar
1 vote
1 answer
497 views

Custom Token Authentication with Craft 3 Login Form

I am building token auth system in Craft 3. https://docs.craftcms.com/v3/dev/examples/login-form.html I used this Login Form. Now I am going to create my own token and save it in user profile. First ...
apollo's user avatar
  • 63
1 vote
1 answer
774 views

How to debug or log some special variables in Craft CMS? (Especially in a controller)

I am going to debug the variables in controller files. But I couldn't figure out how I can debug it and show the values into front-end site or in log files. Do you have any ideas about this? What ...
apollo's user avatar
  • 63
1 vote
1 answer
285 views

Fetch Entries with Tags Only

I'm trying to get all the entries which have tags associated with them. At the moment I'm doing: $entries = Entry::find()->with('tags')->all(); and then filtering the results in PHP as ...
Alk's user avatar
  • 123
1 vote
1 answer
1k views

Select specific fields from query

I'm trying to get tags out of the underlying craft DB and serve it as a REST endpoint - however, I'm only interested in exposing the tag id and title, so my data should look like this: {id: 1, title:...
Alk's user avatar
  • 123
1 vote
1 answer
115 views

Steps for integrating an HTML design to a website page and managing its content from backend

I am a beginner to Craft CMS. I have an HTML design for Craft integration. I need to covert this to a live URL page on my website. Also, I need to manage its content from the backend. I think we need ...
Rakhi Vijayan's user avatar
0 votes
0 answers
220 views

Contact form plugin ajax submit URL not working

I am using contact form plugin for forms in my craft website. For avoiding page redirection, I followed ajax submit for the form, but it is not redirected to controller code. My form is as below:- ...
Rakhi Vijayan's user avatar
1 vote
1 answer
405 views

How to pull an entry's SEOmatic meta tags with Element API?

How do I get the meta tags used in SEOmatic for a specific entry and returning it through the Element API? Not sure how the PHP code looks like when using SEOmatic's PHP API.
kayq's user avatar
  • 77
2 votes
1 answer
110 views

Craft 2 FormBuilder 2 equivalent plugin in Craft 3

Is there any plugin equivalent to Craft 2 FormBuilder 2 plugin in Craft 3? My Craft 2 website forms are built with FormBuilder 2. I upgraded the website to Craft 3, but FormBuilder 2 is not working. I ...
Rakhi Vijayan's user avatar
3 votes
1 answer
595 views

How to get current site (locale) api / plugin

For my form plugin I'm using a global set of fields. These can be set in 2 languages default and en. Problem is whenever I try to output them I cant dynamically make them use the current site locale/...
J.Dekkers's user avatar