<?php
class Controller_Ajax extends Controller {
public function action_send()
{
$status = Model_Ajax::send_email();
echo json_encode($status);
}
}
/* End of file ajax.php */
<?php
class Model_Ajax extends Orm\Model {
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array('before_insert'),
'Orm\Observer_UpdatedAt' => array('before_save'),
);
public static function send_email()
{
$message = "test";
$last_not_sent = Model_Camping::find()->where("flag_sent", "0")->order_by('id', 'desc')->limit(1)->get_one();
$emails = Model_Camping::find()->where("flag_sent", "0")->limit(10);
$emails_total = $emails->count();
$emails = $emails->get();
if(false == $emails)
return array("message" => "All emails has been sent.", "status" => "1");
$i = 1;
foreach($emails as $recipient)
{
$mail = Email::factory(); // I use SMTP on config
$mail->to($recipient->email);
$mail->from("example@domain.tld");
$mail->subject("FuelTest - Mail $i");
$mail->message($message);
if(false === $mail->send())
{
echo $mail->print_debugger();
return "Error";
}
$camping = Model_Camping::find($recipient->id);
$camping->flag_sent = 1;
$camping->sent_at = time();
$camping->save();
//$result = DB::update('campings')->value("flag_sent", "1")->where('id', '=', $recipient->id)->execute(); // <- with this happens the same as doing like above
$i++;
}
if($recipient->id == $last_not_sent->id)
return array("message" => "All the e-mails has been sent.", "status" => "1");
else
return array("message" => "$emails_total emails sent.", "status" => "0");
}
}
/* End of file ajax.php */
<?php
class Model_Camping extends Orm\Model {
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array('before_insert'),
'Orm\Observer_UpdatedAt' => array('before_save'),
);
}
/* End of file campings.php */
Warning! ErrorException [ Warning ]: in_array() expects parameter 2 to be array, null given OREPATH/classes/error.php @ line 131126 * @param Exception $e the exception to show 127 * @return void 128 */ 129 public static function show_php_error(\Exception $e) 130 { 131 $fatal = (bool)( ! in_array($e->getCode(), \Config::get('errors.continue_on'))); 132 $data = static::prepare_exception($e, $fatal); 133 134 if ($fatal) 135 { 136 $data['contents'] = ob_get_contents();
Variable #1: NULL Variable #1: NULL
Variable #1:
array(6) {
["type"]=>
string(5) "mysql"
["connection"]=>
array(5) {
["hostname"]=>
string(9) "localhost"
["database"]=>
string(6) "vienna"
["username"]=>
string(7) "ipalaus"
["password"]=>
string(7) "soyroot"
["persistent"]=>
bool(false)
}
["table_prefix"]=>
string(0) ""
["charset"]=>
string(4) "utf8"
["caching"]=>
bool(false)
["profiling"]=>
bool(false)
}
Variable #1:
NULL <- so, the database type is lost and Exception throw.
<?php
class Model_Ajax extends Orm\Model {
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array('before_insert'),
'Orm\Observer_UpdatedAt' => array('before_save'),
);
public static function send_email()
{
$message = "test";
$last_not_sent = Model_Camping::find()->where("flag_sent", "0")->order_by('id', 'desc')->limit(1)->get_one();
$emails = Model_Camping::find()->where("flag_sent", "0")->limit(10);
$emails_total = $emails->count();
$emails = $emails->get();
if(false == $emails)
return array("message" => "All emails has been sent.", "status" => "1");
$i = 1;
//should update all the rows
$result = DB::update('campings')->value("flag_sent", "1")->where('flag_sent', '=', 0)->execute();
//now loop through the array and send an email
foreach($emails as $recipient)
{
$mail = Email::factory(); // I use SMTP on config
$mail->to($recipient->email);
$mail->from("example@domain.tld");
$mail->subject("FuelTest - Mail $i");
$mail->message($message);
if(false === $mail->send())
{
echo $mail->print_debugger();
return "Error";
}
$i++;
}
if($recipient->id == $last_not_sent->id)
return array("message" => "All the e-mails has been sent.", "status" => "1");
else
return array("message" => "$emails_total emails sent.", "status" => "0");
}
}
$sent = array();
foreach($emails as $recipient)
{
$mail = Email::factory();
$mail->to($recipient->email);
$mail->from("examle@localhost", "my name");
$mail->subject("FuelPHP Test - Mail $i");
$mail->message($message);
if(false === $mail->send())
{
echo $mail->print_debugger();
return "Error";
}
$sent[] = $recipient->id;
$i++;
}
Debug::dump($sent);
$result = DB::update('campings')->value("flag_sent", "1")->where('id', 'in', $sent)->execute();
ErrorException [ Warning ]: in_array() expects parameter 2 to be array, null given COREPATH/classes/error.php @ line 131126 * @param Exception $e the exception to show 127 * @return void 128 */ 129 public static function show_php_error(\Exception $e) 130 { 131 $fatal = (bool)( ! in_array($e->getCode(), \Config::get('errors.continue_on'))); 132 $data = static::prepare_exception($e, $fatal); 133 134 if ($fatal) 135 { 136 $data['contents'] = ob_get_contents();
Isern Palaus wrote on Saturday 2nd of July 2011:Hello, How I can check that I'm on RC-3.0? Because I'm checking out from Github and switching to 'develop' from core and orm... I can check that I'm on develop with core becuase of the change we made the other day but how I can recognize the orm problem? Thank you
Isern
* develop masterthe * means you're on develop also go to packages/orm and type:
ipalaus@tear core % git branch * develop master ipalaus@tear core % cd ../packages/orm ipalaus@tear orm % git branch * develop master ipalaus@tear orm
COREPATH/classes/error.php @ line 131 126 * @param Exception $e the exception to show 127 * @return void 128 */ 129 public static function show_php_error(\Exception $e) 130 { 131 $fatal = (bool)( ! in_array($e->getCode(), \Config::get('errors.continue_on'))); 132 $data = static::prepare_exception($e, $fatal); 133 134 if ($fatal) 135 { 136 $data['contents'] = ob_get_contents();
It looks like you're new here. If you want to get involved, click one of these buttons!