Question

I am designing an Email controller with actions like actionRegisterEmail and actionForgotPasswordEmail. This would help me to view the emails in browser also while assigning dummy data if data is not set.

class EmailController extends Controller
{
    public $layout='email';

    public function actionForgotEmail(ResetPasswordEmail $forgotModel=null){
        if($forgotModel == null){
            $forgotModel = new ResetPasswordEmail;
            $forgotModel->name = "John Doe" ;
            $forgotModel->link = "a url" ;
        }
        return $this->render('reset_password',$forgotModel);
    }

}

When I'll be sending this emails I will be instantiating the controllers and fetching their returned html which they return with $this->render. The idea is good according to me but yii doesn't allow me to call action methods on instantiated controllers like

 $emailController = Yii::app()->createController('email');
 $vary = $emailController->actionForgotEmail($reset);
 todb_and_mail($vary);

. This way I can mail the rendered html and also test with dummy. But I have come across many posts which says do not instantiate controller use components.But I want to have a seperate view and pass data to it.Do we have any more simpler alternative ?

Was it helpful?

Solution

Just to help anyone with the same doubt.I instantiated a dummy controller and set its layout and called the render method then.

class MailHelper extends CComponent {
    public static function getEmail($view_template,$data){
        $controller = new CController('Email');
        $controller->layout = "email" ;
        return $controller->render($view_template, $data, true);
    }
}

This way I can get the functionality of passing variables and data to view.We are using static html for visibility of the view files directly from the browser, this was actually simple I made it complicated to get the other things involved thanks davey for guiding me right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top