This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Impossible to write a simple : setIsActivated() function
icon8.gif  Impossible to write a simple : setIsActivated() function [message #103444] Tue, 03 August 2010 02:22 Go to next message
anxious  is currently offline anxious
Messages: 38
Registered: June 2010
Location: France
Member
Hello, it's been 1h30 that we're working on a SIMPLE function that do not work Very Happy

I'm on the backend, and i need to validate offers to make them appear public on the wesite. (plus, it send a mail to alert the user)

either it doesn't save (i click on activate, then save, it doesn't send the mail and it doesn't save the is_activated = true.



public function setIsActivated($value)
	{

	  if ($value == false)
	  {

	    sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');

	    $email = $this->getSfGuardUser()->getProfile()->getEmail();
	    $message = sfContext::getInstance()->getMailer()->compose(
	                            'no-reply@site.com',
	                            $email,
	                            'your offer has been published / votre offre à été publiée',
	                            get_partial('newsletter/activation_offre')
	    );

	    $message->setContentType('text/html');

	    sfContext::getInstance()->getMailer()->send($message);
			$this->isActivated = true;
			$this->save();
	  } else {

	 	$this->isActivated = false;
		$this->save();
		}
	}




Thanks for your help !


[Updated on: Tue, 03 August 2010 14:31]

Re: Impossible to write a simple : setIsActivated() function [message #103457 is a reply to message #103444 ] Tue, 03 August 2010 09:38 Go to previous messageGo to next message
hasc  is currently offline hasc
Messages: 195
Registered: October 2007
Senior Member
Hi,

i would not place the mail logic in the model class. I think it is better to leave it in the controller in this case.

Anyway, if I take a look at the last but one line of code that says:
$this->isActivated = false;

I guess this will be the reason why the property is always false.

Regards
Re: Impossible to write a simple : setIsActivated() function [message #103480 is a reply to message #103457 ] Tue, 03 August 2010 14:30 Go to previous messageGo to next message
anxious  is currently offline anxious
Messages: 38
Registered: June 2010
Location: France
Member
i'm sorry, i didn't past the good code :

here it goes (with the right syntax for IF Very Happy)

public function setIsActivated($value)
	{

	  if ($value == false)
	  {

	    sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');

	    $email = $this->getSfGuardUser()->getProfile()->getEmail();
	    $message = sfContext::getInstance()->getMailer()->compose(
	                            'no-reply@site.com',
	                            $email,
	                            'your offer has been published / votre offre à été publiée',
	                            get_partial('newsletter/activation_offre')
	    );

	    $message->setContentType('text/html');

	    sfContext::getInstance()->getMailer()->send($message);
			$this->isActivated = true;
			$this->save();
	  } else {

	 	$this->isActivated = false;
		$this->save();
		}
	}



It still do not save the status (the checkbox is always disabled !)


but for moving the mail process in the action.class i don't know how to do that, the mail is sending only when i set the offer to active, so it's not indexSuccess, or showSuccess, do you know what i mean ?

[Updated on: Tue, 03 August 2010 14:39]

Re: Impossible to write a simple : setIsActivated() function [message #103482 is a reply to message #103444 ] Tue, 03 August 2010 14:39 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
I'm having to ask this a lot these days: Doctrine or Propel? Very Happy


Remember Palestine
Re: Impossible to write a simple : setIsActivated() function [message #103483 is a reply to message #103444 ] Tue, 03 August 2010 14:40 Go to previous message
anxious  is currently offline anxious
Messages: 38
Registered: June 2010
Location: France
Member
doctrine Very Happy
Previous Topic:problem by accessing the module-index
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software