Fairly new to yii2 and am creating a mailchimp sign up widget I currently have the following in my controller however I was wondering where do I put my code for the post form action etc as I see widgets have run and init but unsure on where to but my mailchimp code that will send the data to mailchimp through the API
Current Widget (Controller)
<?php
namespace common\widgets;
use yii\base\Widget;
use frontend\models\Newsletter;
use yii\data\ActiveDataProvider;
use Yii;
use sammaye\mailchimp\Mailchimp;
/**
* MailchimpWidget
*/
class NewsletterWidget extends Widget
{
public function run()
{
$mc = new Mailchimp(['apikey' => 'xxxxxxxx']);
$mc->lists->getList();
$model = new Newsletter();
return $this->render('newsletterform', [
'model' => $model
]);
}
}
So could I put the signup action in my class NewsletterWidget extends Widget? Or should I create it seperate and then set the action url point to the controller action say in frontend/controllers?
Thank you, I thought that might be the case just wanted to clarify just so I know I am following best practices and keeping my code/folder structure clean.