Questions tagged [controller]

The tag has no usage guidance.

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

How do I call a service from my controller in a plugin?

I'm writing a plugin, and used plugin.io to generate my scaffolding. In my controller I am attempting to call a service, and getting an error. This is my service code from my generated plugin it ...
0
votes
2answers
296 views

How do I wire my form action to my controller action?

I'm writing my first Craft CMS plugin. I have the following tag in my form: <input type="hidden" name="action" value="clientnameDonation/donateForm/donate"> And then I have the following ...
1
vote
0answers
1k views

var_export does not handle circular references” when devMode = true and logDumpMethod = print_r

Here is a similar question that was asked but doesn't resolve my issue Question has changed, see UPDATE below I'm new here so I couldn't just tag a comment onto this post asking this question: I ...
1
vote
1answer
450 views

Update multiple database entries via controller

I've inherited a Craft site that is a mix of a custom plugin (the main site) plus a Laravel Dingo plugin (behind which the bulk of the data in the db lives), plus Solr, and I'm trying to untangle it. ...
2
votes
1answer
157 views

Send an asset from a plugin controller

I have a controller which fetches an asset from an entry (this is the service method that provides the asset): public function findPoster($entryId) { $criteria = craft()->elements->...
3
votes
1answer
872 views

Access data when posting to controller from front-end

I'm writing a plugin to notify authors when a Disqus comment is posted. There is a Disqus JS callback you can use to hook into this, so I'm doing the following on the front-end: this.callbacks....
1
vote
1answer
2k views

Crossdomain ajax request to controller with requireAjaxRequest()

I make request from my localhost(gulp server) to example domain in to VerifyPassword controller. When i make request without headers: {'X-Requested-With': 'XMLHttpRequest'}, It comes as expected 400 ...
1
vote
1answer
435 views

Have a custom plugin do something on every page load?

For an upcoming site build, I'm going to need to capture information on every page load for a number of sections. These will be pages based on standard entries, so I'd prefer to use traditional ...
0
votes
2answers
814 views

How do I properly access plugin controllers from the front-end?

I'm building a plugin, and it all worked just fine until I decided to change the front-end form submission to use AJAX instead of submitting directly. I have a form on the front-end with this action: ...
1
vote
2answers
1k views

Does CSRF protection for controller actions require POST?

I've got a controller action which will work as the callback URL for OAUTH authentication with an external, third-party API. After authenticating, the external API will issue a GET request to my ...
0
votes
1answer
174 views

Fetch matrix field attributes in controller

In my controller I fetched the Entry $criteria = craft()->elements->getCriteria('Entry'); $criteria->section = 'offlineEvents'; $event = $criteria->first(); The Entry has a matrix field ...
1
vote
2answers
161 views

Extending UserController

I'm trying to extend the Craft UserController class, in order to add some extra validation to the actionSaveUser action, before the rest of the code in that function executes. I've got no problem ...
2
votes
2answers
428 views

Passing data back to form on invalid submission

I currently have a form that is being displayed to the user via a custom route. The form submits to a controller. The first thing the controller does is populate a custom model and validates it. If ...
3
votes
2answers
1k views

Controller action redirection when called via route

I have a route set up in routes.php that calls a controller action using something similar to what is described here: https://straightupcraft.com/articles/how-do-i-setup-a-route-to-point-to-a-...
2
votes
1answer
774 views

Controller Action 404

Ok once again I'm having an issue with a plugin controller. It was working once upon a time but stopped sometime in the past year. I have stripped the plugin down to bare, so there is no reason it ...
-1
votes
1answer
106 views

Paypal IPN controller logic? [closed]

Has anybody got a controller (or whatever plugin aparatus is needed) to process Paypal IPN?
0
votes
0answers
41 views

ElementService get entries by field [duplicate]

I'm trying to get all elements whose custom field satisfies a specific value. I've got the ElementCriteriaModel but I'm unsure how to set the field and value I'm looking for, from the documentation $...
1
vote
1answer
956 views

Plugin Controller Ajax Request

I've got a custom controller in my plugin that checks whether or not the request is ajax or not, using craft()->request->isAjaxRequest() In the event that it is, I just want it to return a ...
0
votes
1answer
1k views

Error - Unable to resolve the request

I've created a 'controllers' folder within the 'plugins' folder and a php file within that following the documentation I've also created the following form: <form method="POST" accept-charset=...
0
votes
1answer
2k views

Plugin Controller actions for entering data and redisplaying form or redirecting

I'm getting confused with how to submit forms to a plugin controller as shown briefly in the docs. I'm making a multi-page form, which saves the data on each page to the session, sending it elsewhere ...
4
votes
1answer
154 views

Assets indexing from plugin controller

I am making a dashboard widget to trigger the assets indexing action. I got the controller ready but I do not understand then how to trigger the action. Should I go with AssetIndexTool? Then ...
3
votes
1answer
452 views

can i used craft.entries.section into my Controller

I am new in Craft CMS and this is my first plugin. Below is my code to get products. {% craft.entries.section('products').limit(9) %} This code is working fine but can I use this code in my ...
2
votes
2answers
234 views

Dashboard Widget: Access widget settings from controller / service

i wrote a plugin with an additional dashboard widget. i have to refresh the widget data every hour with ajax. so i added a plugin controller in my plugin directory with the idea of re-rendering the ...
2
votes
1answer
519 views

How to catch errors in a service and return to a controller?

How do you handle “catching” errors in a plugin service and return the error to the plugins controller? To be more specific... I am sending an Ajax request to a controller, that controller is ...
2
votes
1answer
150 views

Issues with returnJson not returning html?

Im running in to issues with returnJson not returning html or just returning and empty object: $userHtml = craft()->logic->renderSiteMacro('_macros/elements', 'listing', $args); $this->...
1
vote
1answer
895 views

How do I pass existing template variables on to an action controller?

In a plugin I am using registerSiteRoutes to route URL requests to a controller to handle some user validation before rendering the appropriate template. For example: public function ...
4
votes
2answers
804 views

Twig Filter in Plugin/PHP?

Is it possible to access twig filters in a plugin? I want to be able to preview how text will look in a textarea using Markdown for a discussion board, it'd be awesome to use ajax to send the content ...
1
vote
1answer
499 views

Anonymous access to controller action fails

I have this controller, and I've set $allowAnonymous to true, but I'm still getting redirect to CP login: class SitemapController extends BaseController { protected $allowAnonymous = true; ...
1
vote
1answer
1k views

Call Controller Method with Plugin

Is it possible to call a method of a plugin's controller from within a plugin? I don't plan on making a habit of this but sometimes it may be needed. Just trying to plan ahead. Thanks!
4
votes
2answers
211 views

Is it typical that data is fetched from within templates rather than in controllers?

I'm assessing Craft's suitability for my next project, coming from using HMVC in CodeIgniter with a custom CMS. In CI all requests go via a controller action which is responsible for inspecting ...
3
votes
1answer
503 views

How to tell if user exists

I am automatically creating users in a service, is there a way to check if user exists? I want to log in id user exist or save a new user if it doesn't, I have the following so far which will add a ...
1
vote
2answers
625 views

Trouble posting to plugin controller

I'm working on a plugin to do subscription billing with paypal. I have the following controller class PaypalSubscription_SubscriptionController extends BaseController { public function ...
5
votes
1answer
2k views

Rendering templates from plugin controller

Right now I'm trying to accomplish routing users through a controller action before rendering the plugin's CP template... [Plugin]Plugin.php // ... public function registerCpRoutes() { return [...
1
vote
1answer
250 views

How do you route an entry or category URI to a plugin controller?

Craft's documentation states: "If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded". Instead of loading the template, how can I set the route to ...
5
votes
3answers
650 views

How can I set the HTTP status code?

I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin. Yii has a response object where the code can be set, but I can't find a way to access it from craft.
3
votes
1answer
2k views

Controller action works but still gives 404

I'm writing my first plugin and I'm slowly getting there, but I hit on a problem: I have a controller class in which I have a function that sets a cookie. I call on this function from within a ...
2
votes
2answers
795 views

Constructor in custom controller?

I'm implementing a custom controller as part of a plugin I'm building. There's some set up work that I'd like to do in the controller's constructor. I created a __construct method, and it seems to ...
1
vote
1answer
244 views

MVC - Should these be seperate controllers/models etc

I hope this is the right place to post this, it's more a question on MVC for plugin development. I'm developing a plugin to extend SproutForms to add users to Campaign Monitor lists. So far I've got ...
5
votes
1answer
1k views

How to return errors from a model back to the template?

I'm working on validation with Craft. I have a custom plugin that allows public submission. However, I want to make sure I can pass errors back to the template. The key is trying to make my code as "...
4
votes
1answer
790 views

How can I ensure using actionUrl in my template does not show script name in the generated URL?

I have an controller action in my custom plugin that processes Paypal IPN requests. How it works is that you provide a URL for Paypal to send it's notification requests to and then process them and ...
1
vote
1answer
158 views

Direct relation between templates and PHP

Is there a direct relation between code in templates and PHP code inside a controller for example? I need to translate {% set relatedProducts = craft.entries.section('products').relatedTo({ ...
4
votes
1answer
2k views

Cannot post data to a plugin controller action

I have a form in one of my templates <form method="post" action="" accept-charset="UTF-8"> <input type="hidden" name="action" value="paypalPayments/payment/pay"> [...] </...
2
votes
1answer
198 views

Insert action in front of template, while maintaining entry slug

We are attempting to implement a number of Pardot forms within Craft templates. Since Pardot's form actions do not allow us to dynamically specify a return URL, our best choice is to use the form's ...
2
votes
1answer
1k views

Using the required field validation in custom element types/plugins?

I am finishing up the last few details on my custom element type. I have custom statuses and public submissions working. The last detail is providing validation on custom fields set through the field ...
6
votes
1answer
620 views

Allow anonymous submission on a custom element type?

I have a custom element type that I want to allow anonymous submission from the front-end. I have a solid concept on how the form data is passed but I seem to be missing something. I have the ...
1
vote
1answer
814 views

How to perform a redirect and pass on data?

I have a Controller Action which should pass on some data from one (CP) template to another: Template 1 (plugin/form): Form sends data Controller redirects data to Template 2 Template 2 (plugin/): ...
3
votes
1answer
994 views

How do I update a column value in my custom plugin with a simple controller?

I have a custom element type with its own table 'pluginname_entries'. I am trying to find a way to "dummy proof" changing the plugins status. So I came up, aka stole from the Events element type, with ...
7
votes
2answers
746 views

Best way to use custom enums in my plugin templates?

I am building a plugin that's uses an enum for custom statuses. The statuses are integrated within my plugin with the exception of changing the status in my template code. pluginname/enums/...
3
votes
2answers
2k views

Direct access to controller

I'm trying to create a plugin with a controller, but I don't want to render any view but run a script from a cronjob. I can't get into the controller with an url and I'm not sure why. I already ...
4
votes
1answer
987 views

Is the “registerSiteRoutes” hook screwing up my template path?

This may be a bug... I have a controller action which has been working great. It's a simple action with a single purpose... load a template with an internal value. public function actionMyAction() { ...