We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [controller]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
33 views

Finding the correct actions url

struggling to decipher how to link a plugins controller to an action route. The docs say to use "https://pluginfactory.io/" to scaffold one, but what it generates is a different structure to what the ...
1
vote
0answers
23 views

How can I override the Response status text from a controller?

I'm trying to set the statusText in a response, from a module controller. E.g.: <?php namespace modules\appmodule\controllers; use Craft; use craft\web\Response; class StatusController extends ...
1
vote
1answer
29 views

Does Craft automatically sanitize user input?

Can I rely on Craft to clean user input, is safe to save the following data like in the below example function, if not, what is the Craft best practice for cleaning(making it safe) user input? public ...
0
votes
1answer
24 views

Action route not available from URL. What do I have wrong?

I built a plugin for Craft 3 and need to run one of its actions via CRON. I know I can set this up as a console command, and will do that, but before I get there, I'd like to solve this issue. I ...
2
votes
1answer
198 views

What are the different scenarios to plan for when using $allowAnonymous in a controller?

Craft 3.2 updates how the allowAnonymous behavior works. I have things working in our plugins but I don't understand the different syntaxes needed across our different allowAnonymous use cases. For ...
1
vote
1answer
41 views

Get entries based on multiple fields in controller

I am trying to get the entries based on multiple fields. Fields can be of type tags, checkbox, radio box, and number. In my controller currently what I tried is. $extrafilter will be like Array ( ...
0
votes
0answers
46 views

How to hook into root controller to redirect any route based on some criteria?

We have a use case where if our user account has a certain flag that they are redirected to a specific page. Is there a way to hook into the root controller or some sort of router mechanism such that ...
3
votes
1answer
51 views

How to re-populate form with old values when submitted from a controller?

I have a form in a template which makes a request to the specified action (a controller). The controller decides that there is an issue with the inputs and needs to provide error output for the user. ...
0
votes
0answers
16 views

Injecting filename into all templates?

I found a topic about getting the current filename for templates here: How can I make a template output its own filename? but I am curious, is there some way I can get the server to implement this ...
0
votes
0answers
36 views

Is it possible to use craft()->runController with variables in Craft 2

I'm trying to run a plugin 1 controller from plugin 2. I can get it to run and re-direct to plugin 1's controller but as it is not being run with posted variables I need to be able to tell plugin 1's ...
1
vote
1answer
174 views

How do I correctly send an external request to a module controller? runAction() is returning null

Craft 3.1.18 I have a simple controller VeteransController made using the updated Business Logic module. The purpose of this controller is to create a very simple endpoint for an external Vue ...
1
vote
1answer
130 views

Craft 3 Controller - Redirect with errors

I cant get this to work. I'm doing a post to a controller action. From that action I'm doing a lot of validations, db insert, file uploads etc. Coming from Laravel Im used to is doing like this: (...
2
votes
1answer
46 views

Update a lightswitch field in Craft CMS 2

How can I edit a lightswitch field in an entries field layout via PHP? This is my current approach public function actionSponsoredEntriesPriority() { $this->requireAdmin(); $this->...
1
vote
2answers
70 views

renderTemplate() renders the twig file without any CSS

I've set up the routing for a specific URL in my plugin to trigger the actionIndex controller method. I after logging a message to the Craft logs, I want to return the rendered twig file as the view, ...
2
votes
2answers
730 views

How to render plugin templates in Craft CMS 3?

I cannot find a way to render templates from a plugin controller in Craft 3. I feel as though I've tried every variation advised online but for some reason this still isn't working. <?php ...
2
votes
1answer
50 views

Some (but not all) controller action routes return 404 on staging server

I've created a module for a project that has several actions, all of which are called through AJAX. Each is a post request that sends over any required params plus the CSRF token using the method ...
1
vote
2answers
788 views

Action URLs from CP to a Craft 3 plugin controller

I'm working on my first Craft 3 plugin and want to add some buttons to my plugin's control panel section which post form data to a controller. My plugin is called 'myplugin', the controller I wish to ...
1
vote
1answer
107 views

How can I pass a variable defined in a Controller to my variables?

In my Craft 3 plugin I would like to pass a variable defined in my Controller to my PluginVariable.php file. Is this possible?
1
vote
2answers
227 views

How to disable plugin Disable and Uninstall?

I am developing a site with a customer logged in area. I don't want anyone to access the section if they are logged out and instead redirect them to the login form. I could just add {% requireLogin %...
1
vote
1answer
96 views

How can I call console controllers

I have a controller in the console folder. How can I call this controller via ajax please? I tried to config a route in Routes.php, and then call this route by jquery Get() function. But none of ...
1
vote
1answer
737 views

“Template Not Found” error when trying to access a module controller action

I'm a total Craft newbie, so I hope this question isn't ridiculous. I just want to see a controller / action work in my new module. I have src/controllers/ScrapeController.php as such: <?php ...
1
vote
0answers
335 views

Unable to call a service method from controller in my custom plugin

I know there are similar questions here, but I don't see a definitive answer, nor one that works for me. I've generated a plugin via pluginfactory.io, which has some controllers and a single service. ...
2
votes
1answer
643 views

Craft 3 Controller giving 404

Updating a plugin to Craft 3 (also changed its name). I know this is probably something very simple, like capitalization, but can anyone point out what's wrong? Firefox console shows a 404 for http://...
2
votes
2answers
131 views

Add a button to the entry edit screen via plugin

I would like to add a button to the edit entry screen, only for already saved entries, alongside the "Share" button. When clicked, I'd like to call my plugin's controller action and post the entry ID....
1
vote
1answer
1k views

How to call Controller in Module?

I'm very new to craft and I'm having trouble finding an answer to my question (I've scoured the questions on here - but the only answers appear to be for plugins). Basically, I want to submit a form ...
0
votes
0answers
395 views

Plugin Development (Craft 3): Pass variables with redirection

I'm building out a Craft 3 plugin and can't see who to pass variables with redirection from a controller. For example, I have a controller that I want to pass back to the defined redirect value ...
1
vote
1answer
129 views

How to render template instead of throwing an error?

I'm working on a plugin that hooks into Craft's Guest Entries plugin. I want to send a confirmation mail after an entry has been saved. This works nicely so far. Now I want to catch any errors in ...
1
vote
1answer
306 views

Filter entries by ajax to controller

Short story: I need your help sending value from dropdown selection as data to controller so my div updates with the filtered entries based on the selection. Long story and code: I have a listing of ...
2
votes
0answers
453 views

Craft 3 Plugin - Only default action works

I'm working on a Cloudflare integration plugin for Craft 3. I set up the plugin with settings, which works fine so far. Now I intended to verify the Cloudflare credentials using an AJAX call. I set ...
1
vote
1answer
73 views

Save Entry Data as CSV and Email it to the Author / Logged in User

I am trying to email some Entry data that they have created in CSV Format to the author/logged in user. I have a controller setup with a frontend form posting an action to the controller: public ...
1
vote
1answer
51 views

Posting children to a Structure

This question is a follow up of a previous question see: (Entry Form - Multiple Entries & Entry Type & Parent) I am trying to add multiple children to a pre-existing multi level structure: ...
3
votes
2answers
324 views

Query entries relatedTo multiple categories in controller

I have an AJAX GET call that should count all the products matching three different taxonomies. Product families Sectors of application Liquids suitable for the product so in the form the user ...
1
vote
1answer
40 views

Craft plugin services in subfolders

So I'm getting to a point where I have a lot of services in a particular plugin, and I would like to organize my plugin services into sub-folders. I've tried a couple ways but the controllers don't ...
1
vote
1answer
641 views

Ajax call to action 404

I've a trigger on my frontend that requires an action. I've started from the businessLogic template but I'm getting a 404 and can't find why. My function public function actionExampleAjax() { ...
1
vote
3answers
493 views

Craft CMS plugin with AJAX gives 404 error

I have created a small craft cms plugin to pull some information from the DB, and everytime I execute the plugin I get a 404. Here is the controller namespace Craft; class ...
1
vote
1answer
710 views

Error 404 When trying to POST to plugin Controller action

Before I dive into my problem, I do want to mention that I did do my due diligence and spent the last two days researching this problem, to no avail, so here it goes: So I'm getting the following ...
4
votes
1answer
84 views

Store categories in array by level in controller

I'm making a plugin and I need to get an array from a certain category group where the levels of the array are the same as the level of the categories in the group. So I used the following code to ...
1
vote
0answers
44 views

Find category through ajax using ElementCriteriaModel

I'm trying to run a controller action with ajax in a new plugin I'm making. The action needs to return all categories from a group, so nothing impossible here. When I run the actionUrl in the ...
1
vote
1answer
238 views

Trouble calling a plugin's controller function from within an event listener function

I am working on extending the formbuilder2 plugin to call and pass the $event variable to a custom Controller after FormBuilder2 has initialized the "onBeforeSave" event within the FormBuilder2 ...
0
votes
1answer
129 views

How do I set a controller for my homepage

How can I set a controller for the homepage? I can't seem to find any way to override the default route to the homepage. I need to call an action from the homepage and can't find any examples of this ...
1
vote
1answer
473 views

Plugin's action URL not working and showing 404 error

I created a plugin to schedule some custom email notifications. The action URL is working perfectly on localhost but isn't working on stagings server. Is it related to any server stuff.
1
vote
1answer
107 views

No template found when accessing action method per route

I want to render a (non-CP) template from an action method in my plugin controller over a route I defined in the plugin base class: function registerSiteRoutes() { return array( 'myservice' =&...
2
votes
1answer
988 views

What should my controller return in a Craft.postActionRequest

Simple question: I made a button in my plugin settings that creates a Craft.postActionRequest but what should the controller return? It does not need to return anything else than true (successful) or ...
1
vote
1answer
261 views

Trouble passing errors back to form through setRouteVariables

This has me a bit stumped. I have two forms - posting to two different actions within the same controller. On error I am attempting to have them both display a flash-notice, as well as pass the model ...
1
vote
1answer
229 views

How do you get all the categories in a category group in a controller?

I want to get all the categories in a specific category group inside my controller. How do you do that?
0
votes
1answer
320 views

How to handle entry save in plugin when entryId is not set?

Referring to my older question, I have the entryId working on an existing entry. However I've noticed a new entry doesn't have an entryId set (makes sense). I have some custom information in text ...
4
votes
1answer
966 views

Creating sessions in Twig

I am trying to create the PHP $_SESSION equivalent in Craft CMS using Twig. I have searched very long and I can't find how you can create sessions in Twig. In previous posts I have found that I ...
1
vote
1answer
150 views

Cache controller/action

Does Craft have a built-in Controller/action for clearing the cache? We have auto-deployment set to a server and would be useful to set up a POST-receive hook to force the cache to clear when ...
1
vote
1answer
385 views

Call Craft controller with cron job

I am making a plugin which has a controller to be called every hour. My server environment is using Anacron. So I wrote this anacron job: 1@hourly 0 cron.hourly wget http://www.mydomain.com/actions/...
2
votes
1answer
295 views

Business Logic Controller for Validating Address in Commerce

I am putting together my Business Logic plugin, as I want to validate the address fields throughout the checkout process of my Cart. I understand in order to do this I need to create a plugin and us ...