Rendering of blank view

Hi guys,

I’m not too familiar with Yii yet, but trying to get there. I have a couple of questions, regarding importing extensions, and debugging of view rendering in failing cases. Here’s my problem and code:

I am trying to use PHPMailer code in my application. I’ve put it in the extension folder, and in the config:




'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.extensions.PHPMailer_v5.1.*',

	),



Using this with a Yii::import statement in the model class I am working on gave me an “cannot open stream” error when instantiating a new PHPMailer object. So this is what i’ve got now:




public function sendRegistrationMail() {

		try {

			require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.phpmailer.php';

			require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.smtp.php';


			$mail             = new PHPMailer();


			$body             = $mail->getFile('contents.html');

			$body             = eregi_replace("[\]",'',$body);


			$mail->IsSMTP();

			$mail->SMTPAuth   = true;                  // enable SMTP authentication

			$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier

			$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server

			$mail->Port       = 465;                   // set the SMTP port


			$mail->Username   = "";  // GMAIL username

			$mail->Password   = "";            // GMAIL password


			$mail->From       = "";

			$mail->FromName   = "Webmaster";

			$mail->Subject    = "This is the subject";

			$mail->AltBody    = "This is the body when user views in plain text format"; //Text Body

			$mail->WordWrap   = 50; // set word wrap


			$mail->MsgHTML($body);


			$mail->AddReplyTo("","Webmaster");


			$mail->AddAddress("","");


			$mail->IsHTML(true); // send as HTML

			$mail->Send();

		}

		catch (Exception $e) {

			Yii::trace(CVarDumper::dumpAsString($e->getTraceAsString()));	

		}

		return true;

	}



The code snippet above is called from my afterSave() method:




public function afterSave() {

		$this->sendRegistrationMail();

		return parent::afterSave();

	}



What is happening after the save is the rendering of a view, however I do not get that far, I get a blank page. The model gets saved, so it is sendRegistrationMail that fails.

My questions are, how to import extensions in a cleaner way than in the method? because this is not very clean.

And if there are any good ways of debugging why the function fails. I get nothing in any logging. And I feel a bit helpless with no feedback as to why.

Hope someone can share some knowledge :slight_smile:

Cheers!

Hi olemara,

I am not sure what you have turned on for logging. Would be interested if others are taking advantage of another means but here is what I use.


'db'=>array(

...

  'enableProfiling'=>true,

  'enableParamLogging' => true,

),

	


'log'=>array(

  'class'=>'CLogRouter',

  'routes'=>array(

    array(

      'class'=>'CFileLogRoute',

      'levels'=>'error, warning',

    ),

    array(

      'class'=>'CWebLogRoute',

    ),

    array(

      'class'=>'CProfileLogRoute',

      'levels'=>'profile',

      'enabled'=>true,

    ),


  ),

),

These are just dups of your config ‘import’=>array so shouldn’t be needed.




require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.phpmailer.php';

require Yii::app()->basePath. '/extensions/PHPMailer_v5.1/class.smtp.php';

I have only set up PHPMailer once with Yii awhile ago and although I got it working I changed to a different means.

All you have to do is put phpmailer.php in your components folder and call $mail = new phpmailer();

Hi enfield,

and thank you for your reply. Yes, I thought that those imports in the method where duplicates, and that it should have been enough with the one in the config. But I keep getting an “include(PHPMailer.php): failed to open stream: No such file or directory” if I don’t. Weird. I also tried to move it to components as you suggested, and the above mentioned error persist.

Might there be something wrong with my setup? I have checked file rights as well.

Good suggestion about the logging, the DB logging gives nice stats. But when something goes wrong as mentioned in my first post, nothing gets logged. Seems like the request has to be successful for the logging to take place.

Any other suggestions would be highly appreciated.

Cheers

Some new info:

The error "include(PHPMailer.php): failed to open stream: No such file or directory" I should maybe have seen before. When extracting the PHPMailer tar ball the class name is "class.phpmailer.php", which contains the PHPMailer class. I renamed the file to PHPMailer.php and it worked.

I think however that this solution can be kind of "confusing", especially when one can use wildcards in the imports. Now, if I want to use/instantiate an object of "phpmailerException" which is in the same file, I have to copy it to a new file and import it. Is there a way to work around this? Having a smoother way of importing classes?

BTW, I am still wondering of how to debugg something that stops in the middle of the execution (it seems) not giving any clues of why.

Appreciate any thoughts