I keep getting the following error while trying to using __toString():
Catchable fatal error: Object of class Address could not be converted
to string in C:wamp\www\demo.php on line 36
Where did I go wrong?
demo.php
echo '<h2>Instantiating Address</h2>';
$address = new Address;
echo '<h2>Empty Address</h2>';
echo '<tt><pre>' . var_export($address, TRUE) . '</pre></tt>';
echo '<h2>Setting properties...</h2>';
$address->street_address_1 = '555 Fake Street';
$address->city_name = 'Townsville';
$address->subdivision_name = 'State';
$address->postal_code = '12345';
$address->country_name = 'United States of America';
echo '<tt><pre>' . var_export($address, TRUE) . '</pre></tt>';
echo '<h2>Displaying address ...</h2>';
echo $address->display();
echo '<h2>Testing magic __get and __set</h2>';
unset($address->postal_code);
echo $address->display();
echo '<h2>Testing Address __construct with an array</h2>';
$address_2 = new Address(array(
'street_address_1' => '123 Phony Ave',
'city_name' => 'Villageland',
'subdivision_name' => 'Region',
'postal_code' => '67890',
'country_name' => 'Canada',
));
echo $address_2->display();
echo '<h2>Address __toString</h2>';
echo $address_2;
?>
oop.php
<!DOCTYPE html>
<html>
<head><title>OOP</title></head>
<body>
<?php
class Address {
public $street_address_1;
public $street_address_2;
public $city_name;
public $subdivision_name;
public $country_name;
protected $_postal_code;
// Primary key of an address
protected $_address_id;
// When the recorded created and last updated
protected $_time_created;
protected $_time_updated;
/*
Constructor
#param array data optional array of property names
*/
function __construct($data = array()) {
$this->_time_created = time();
// Ensure that the address can be populated.
if(!is_array($data)){
trigger_error('Unable to construct address with a ' . get_class($name));
}
// If there is at lease one value, populate the Address with it
if(count($data) > 0) {
foreach($data as $name => $value){
// Special case for protected properties
if(in_array($name, array(
'time_created',
'time_updated',
))){
$name = '_' . $name;
}
$this->$name = $value;
}
}
}
/*
Magic __get
#param string $name
#return mixed
*/
function __get($name){
// Postal code lookup if unset.
if (!$this->_postal_code){
$this->_postal_code = $this->_postal_code_guess();
}
/*
Magin __set.
#param string $name
#param mixed $value
*/
function __set($name, $value){
// Allow anything to set the postal code.
if ('postal_code' == $name){
$this->$name = $value;
return;
}
// Unable to access property; trigger error,
trigger_error('Undefined or unallowed property via __set(): ' . $name);
}
/*
Magic __toString
#return string
*/
function __toString() {
return $this->display();
}
$protected_property_name = '_' . $name;
if(property_exists($this, $protected_property_name)){
return $this->$protected_property_name;
}
// unable to access property; trigger error
trigger_error('Undefined_property via __get: ' . $name);
return NULL;
}
/*
Guess the postal code given the subdivision and city name.
#todo Replace with a database lookup
#return string
*/
protected function _postal_code_guess(){
return 'LOOKUP';
}
/*
display an address in HTML
return string.
*/
function display(){
$output = '';
// Street address
$output .= $this->street_address_1;
if ($this->street_address_2){
$output .= '<br />' . $this->Street_address_2;
}
// City, Subdivision Postal
$output .= '<br />';
$output .= $this->city_name . ', ' . $this->subdivision_name;
$output .= ' ' . $this->postal_code;
// Country
$output .= '<br />';
$output .= $this->country_name;
return $output;
}
}
?>
</body>
</html>
function __get() isn't properly closed. I`ve removed some code to make it work. Check for differences.
<?php
class Address {
public $street_address_1;
public $street_address_2;
public $city_name;
public $subdivision_name;
public $country_name;
protected $_postal_code;
// Primary key of an address
protected $_address_id;
// When the recorded created and last updated
protected $_time_created;
protected $_time_updated;
/*
Constructor
#param array data optional array of property names
*/
function __construct($data = array()) {
$this->_time_created = time();
// Ensure that the address can be populated.
if(!is_array($data)){
trigger_error('Unable to construct address with a ' . get_class($name));
}
// If there is at lease one value, populate the Address with it
if(count($data) > 0) {
foreach($data as $name => $value){
// Special case for protected properties
if(in_array($name, array(
'time_created',
'time_updated',
))){
$name = '_' . $name;
}
$this->$name = $value;
}
}
}
/*
Magic __get
#param string $name
#return mixed
*/
function __get($name){
// Postal code lookup if unset.
if (!$this->_postal_code){
$this->_postal_code = $this->_postal_code_guess();
}
$protected_property_name = '_' . $name;
if(property_exists($this, $protected_property_name)){
return $this->$protected_property_name;
}
// unable to access property; trigger error
trigger_error('Undefined_property via __get: ' . $name);
return NULL;
}
/*
Magin __set.
#param string $name
#param mixed $value
*/
function __set($name, $value){
// Allow anything to set the postal code.
if ('postal_code' == $name){
$this->$name = $value;
return;
}
// Unable to access property; trigger error,
trigger_error('Undefined or unallowed property via __set(): ' . $name);
}
/*
Magic __toString
#return string
*/
function __toString() {
return $this->display();
}
/*
Guess the postal code given the subdivision and city name.
#todo Replace with a database lookup
#return string
*/
protected function _postal_code_guess(){
return 'LOOKUP';
}
/*
display an address in HTML
return string.
*/
function display(){
$output = '';
// Street address
$output .= $this->street_address_1;
if ($this->street_address_2){
$output .= '<br />' . $this->Street_address_2;
}
// City, Subdivision Postal
$output .= '<br />';
$output .= $this->city_name . ', ' . $this->subdivision_name;
$output .= ' ' . $this->postal_code;
// Country
$output .= '<br />';
$output .= $this->country_name;
return $output;
}
}
Related
I'm having a bit of an issue. I just updated my dedicated server to PHP 5.4.17 and seem to be running into some strict standard issues. I can't hide the errors due to the unique way that our server and scripts handle errors, and just changing "public function" to "public static function" doesn't seem to be doing anything at all. Below is the snippet of code that is causing the error. Any help is appreciated.
ERROR MESSAGE
Strict Standards: Non-static method KRecord::new_record() should not be called statically, assuming $this from incompatible context in ../actions_controller.php on line 11
Strict Standards: Non-static method KRecord::sanitize_field_list() should not be called statically, assuming $this from incompatible context in ../krecord.php on line 70
Strict Standards: Non-static method KRecord::set_str() should not be called statically, assuming $this from incompatible context in ../krecord.php on line 72
Strict Standards: Non-static method KRecord::sanitize_field_list() should not be called statically in ../krecord.php on line 94
Strict Standards: Non-static method KRecord::set_str() should not be called statically in ../krecord.php on line 95
Thanks,
Thomas
actions_controller.php
require_once('../action.php');
class ActionsController {
public function ActionsController() {
Action::init();
}
public static function create($fields) {
$action = Action::new_record($fields);
return $action;
}
public function show($id) {
$action = Action::find_by($id);
return $action;
}
public function show_all($condition) {
$action = Action::find_all_by($condition);
return $action;
}
public function update($fields, $condition) {
$action = Action::update($fields, $condition);
return $action;
}
public function create_or_update($fields, $condition) {
// $condition will be: WHERE `day_id` = 123 AND `type` = "lunch"
$action = Action::find_by($condition);
if ( $action ) {
Action::update($fields, $condition);
} else {
// Remember to include all the necessary fields
Action::new_record($fields);
}
return $action;
}
public function destroy($condition) {
$action = Action::destroy($condition);
}
}
actions.php
<?php
require_once('../krecord.php');
class Action extends KRecord {
public static function init() {
KRecord::$tablename = 'mod_ets_actions';
KRecord::$fieldlist = array('id', 'employee_id', 'action', 'parameters', 'action_time');
}
}
krecord.php
<?php
class KRecord {
public static $tablename; // Name of the table
public static $fieldlist = array(); // The list of fields in the table (array)
public function KRecord() {
}
/* Cleans the fields passed into various functions.
If the field is not in list given in the model,
this method strips it out, leaving only the correct fields.
*/
private function sanitize_field_list($fields) {
$field_list = self::$fieldlist;
//print_r($field_list);
foreach ( $fields as $field => $field_value ) {
if ( !in_array($field, $field_list) ) {
//echo "<br/>$field is gone...<br/>";
unset($fields[$field]);
}
}
//print_r($fields);
return $fields;
}
// Setter for $tablename
public static function set_tablename($tname) {
self::$tablename = $tname;
}
// Turns the key-value pairs into a comma-separated string to use in the queries
private function set_str($clean_fields) {
$set_string = NULL;
foreach ( $clean_fields as $field => $field_val ) {
$set_string .= "`$field` = '$field_val', ";
}
$set_string = rtrim($set_string, ', ');
return $set_string;
}
// Assembles the condition string
private function query_str($type, $clean_fields) {
$fieldlist = self::$fieldlist;
$update_str = NULL;
$delim = NULL;
foreach ($clean_fields as $field => $field_val) {
if ( $type == 'where' ) {
if ( isset($fieldlist[$field]['pkey']) ) {
$delim = ' AND ';
$update_str .= "$field = '$field_val'$delim ";
}
} elseif ( $type == 'update' ) {
$delim = ', ';
$update_str .= "$field = '$field_val'$delim ";
}
}
$update_str = rtrim($update_str, $delim);
return $update_str;
}
// Inserts new record into the database
public function new_record($fields) {
$clean_fields = self::sanitize_field_list($fields);
//echo "<br/>".self::set_str($clean_fields)."<br/>";
$q = 'INSERT INTO ' . '`' . self::$tablename . '` SET ' . self::set_str($clean_fields) . ';';
//echo "<br/>$q<br/>";
$r = mysql_query($q) or die(mysql_error());
return;
}
// An experimental method. Do not use without testing heavily
public static function insert_unless_exists($fields, $condition) {
$clean_fields = self::sanitize_field_list($fields);
$q = 'INSERT INTO ' . '`' . self::$tablename . '` SET ' . self::set_str($clean_fields);
$q .= ' ON DUPLICATE KEY UPDATE ' . self::set_str($clean_fields);
$q .= ' WHERE ' . $condition . ';';
/* Don't use replace.. it deletes rows. do some sort of insert/update deal. */
//$q = 'REPLACE INTO ' . '`' . self::$tablename . '` SET ' . self::set_str($clean_fields);
//echo "<br/>$q<br/>";
$r = mysql_query($q) or die(mysql_error());
return;
}
// Updates a record in the data table
public static function update($fields, $condition) {
$clean_fields = self::sanitize_field_list($fields);
$q = 'UPDATE `' . self::$tablename . '` SET ' . self::set_str($clean_fields) . ' WHERE ' . $condition .';';
//echo "<br/>$q<br/>";
$r = mysql_query($q) or die(mysql_error());
return;
}
//Removes a record from the data table
public static function destroy($condition) {
$q = 'DELETE FROM ' . self::$tablename . ' WHERE ' . $condition .';';
$r = mysql_query($q);
return;
}
// Finds one record using the given condition
public static function find_by($condition) {
$q ='SELECT * FROM ' . '`' . self::$tablename . '`' . ' WHERE ' . $condition .';';
//echo "<br/>$q<br/>";
$r = mysql_query($q) or die(mysql_error());
$obj = mysql_fetch_object($r);
return $obj;
}
// Finds 1+ records in the table using the given conditions
public static function find_all_by($condition) {
if ( empty($condition) ) {
$where_str = null;
} else {
$where_str = ' WHERE ' . $condition;
}
$objs = array();
$q ='SELECT * FROM ' . '`' .self::$tablename . '`' . $where_str . ';';
//echo "<br/>$q<br/>";
$r = mysql_query($q) or die(mysql_error());
while ( $o = mysql_fetch_object($r) ) {
if ( $o->id != '' )
$objs[$o->id] = $o;
else
array_push($objs, $o);
}
return $objs;
}
}
?>
It's a notice, not really an error. You've got an interesting server setup if you're not able to disable strict notices....
Following this part of the notice: Non-static method KRecord::new_record() tells us that
in your class KRecord, the method new_record needs to be defined statically, such as:
public function new_record($fields) {
Simply need to be defined statically:
public static function new_record($fields) {
You indicate you've changed them to static, but your code in the question does not indicate that change.
Hello Fellow Stack Over Flow members, I hope you guys can help with me something that I have been unable to figure out. I have been unable to write a class for the below code, I was hoping one of you php experts could help
$obj = new ClassName ();
$obj->setName ('Name of Something');
$obj->price = 500.00;
$obj ['address_primary'] = 'First Line of Address';
$obj->address_secondary = 'Second Line of Address';
$obj->city = 'the city';
$obj->state = 'ST';
$obj->setZip (12345);
echo 'Name :: ', $obj->name, PHP_EOL;
echo 'Price :: $', $obj ['price'], PHP_EOL;
echo 'Address :: ', $obj->address_primary, ' ', $obj->getAddressSecondary (), PHP_EOL;
echo 'City, State, Zip :: ', $obj->city, ', ', $obj ['state'], ' ', $obj->getZip ();
Every time I attempt to write a class it either prints out blank or Web Storm is throwing an error about method not being declared in class.
code I used:
var $name; // House Name
var $price; // Price of House
var $address_1; // Address 1
var $address_2; // Address 2
var $city; // City
var $state; // state
var $zip; // zip
// Class Constructor
function Property($name, $price, $address_1, $address_2, $city, $state, $zip) {
$this->setName = $name;
$this->price = $price;
$this->address_primary = $address_1;
$this->address_secondary = $address_2;
$this->city = $city;
$this->state = $state;
$this->zip = $zip;
}
// Getter/Setter functions
function get_name() {
return $this->name;
}
function set_name($newname) {
$this->name = $newname;
}
function get_price() {
return $this->price;
}
function set_price($newprice) {
$this->price = $newprice;
}
function get_address_1() {
return $this->address_primary;
}
function set_address_1($newaddress_1) {
$this->address_primary = $newaddress_1;
}
function get_address_2() {
return $this->address_secondary;
}
function set_address_2($newaddress_2) {
$this->address_secondary = $newaddress_2;
}
function get_city() {
return $this->city;
}
function set_city($newcity) {
$this->city = $newcity;
}
function get_state() {
return $this->state;
}
function set_state($newstate) {
$this->state = $newstate;
}
function get_zip() {
return $this->setZip;
}
function set_zip($newzip) {
$this->setZip = $newzip;
}}
any code suggestions would greatly be appreciated!
that's kind of a big mess! :) You're mixing setters/getters and direct access, and are using old school constructors. You can clean it up really quickly.
class Property
{
public function __construct($name, $price, $address_1, $address_2, $city, $state, $zip)
{
$this->name = $name;
$this->price = $price;
$this->address_primary = $address_1;
$this->address_secondary = $address_2;
$this->city = $city;
$this->state = $state;
$this->zip = $zip;
}
}
If you set up your class like such with all your variables in the constructor, then you should be using it like:
$obj = new Property(
"Name of Something",
500,
"First Line",
"Second Line",
"City",
"State",
"90210"
);
echo 'Name :: ', $obj->name, PHP_EOL;
echo 'Price :: $', $obj->price, PHP_EOL;
echo 'Address :: ', $obj->address_primary, ' ', $obj->address_secondary, PHP_EOL;
echo 'City, State, Zip :: ', $obj->city, ', ', $obj->state, ' ', $obj->zip;
Marked issues with your code were:
You're mixing members with functions. This kind of stuff in your constructor is major breakage:
$this->setName = $price
You're also mixing substring access [] with -> and using getters on top ->getName(). Be consistent, and in this case, respect the semantic of public variables.
Lastly, you had parameters in your constructor, but weren't using it at all.
Alternative would be to assign values to your constructor signature variables by default to make them optional.
public function __construct($name = "", $price = 0, $address_1 = "", $address_2 = "", $city = "", $state = "", $zip = "" )
And then use the public member access as you had:
$obj = new Property();
$obj->name = "Some Name";
Good luck with your learning.
I got this code
$title = new FullName($reservation->Title, $reservation->Description)
which shows the values Title and Description inside a box, but it does so directly following each other. When the box is too small it does a line break, but only at the exact point of the end of the box. so how can i force a line break between $reservation->Title and $reservation->Description ?
Here is the Full Name Class
class FullName
{
/**
* #var string
*/
private $fullName;
public function __construct($firstName, $lastName)
{
$formatter = Configuration::Instance()->GetKey(ConfigKeys::NAME_FORMAT);
if (empty($formatter))
{
$this->fullName = "$firstName $lastName";
}
else
{
$this->fullName = str_replace('{first}', $firstName, $formatter);
$this->fullName = str_replace('{last}', $lastName, $this->fullName);
}
}
public function __toString()
{
return $this->fullName;
}
}
Not a good way without proper explanation, but a Quick solution
Replace
$title = new FullName($reservation->Title, $reservation->Description)
with
$t = $reservation->Title . "<br />";
$d = $reservation->Description;
$title = new FullName($t, $d);
HTML line break can be inserted as:
$this->fullName = $firstName . '<br />' . $lastName
or with generic (non-HTML) new-line character:
$this->fullName = $firstName . "\n" . $lastName
It is important to use double quotes in last case (").
See the link for working example: http://codepad.viper-7.com/qS7nNv
You can add a third parameter to the class.
class FullName
{
/**
* #var string
*/
private $fullName;
public function __construct($firstName, $lastName, $delimiter = null)
{
$formatter = Configuration::Instance()->GetKey(ConfigKeys::NAME_FORMAT);
if (empty($formatter))
{
if($delimiter) {
$this->fullName = "$firstName $delimiter $lastName";
} else {
$this->fullName = "$firstName $lastName";
}
}
else
{
$this->fullName = str_replace('{first}', $firstName, $formatter);
$this->fullName = str_replace('{last}', $lastName, $this->fullName);
}
}
public function __toString()
{
return $this->fullName;
}
}
then add the delimiter:
$title = new FullName($reservation->Title, $reservation->Description, "<br />");
I'm not very good at this, so I'm sure this is a stupid question.
I have a class:
class debug {
private static $messages = array();
private static $errors = array();
private static $all = array(); // includes both of above
private static $types = array('messages','errors');
public static function add($type, $message) {
if(!in_array($type,self::$types) ) {
self::add('errors','Bad type "' . $type . '" specified when sending this message: ' . $message);
return false;
}
self::$$type[] = $message; // ERROR IS HERE (see below)
self::$all[] = $message; // no error
}
}
I'm calling this from another class in order to debug (Surprise).
debug::add('error', 'Error in ' . __FILE__ . ' on line ' . __LINE__);
PHP error message from error.log:
PHP Fatal error: Cannot use [] for reading in /var/www/lib/lib.php on line 1248
It refers to the above-specified line in the debug class.
EDIT:
What I am trying to do is use a variable variable (hence the posting title) to determine which static array to add data to.
I.e. if $type == 'messages', then $$type == $messages.
So I want self::$$type[] == self::$messages[]
Or if $type == 'errors', then $$type == $errors and self::$$type[] == self::$errors[]
Change the following line to. This ensures that $type is evaluated into 'message' or 'error' first.
self::${$type}[] = $message;
To expand on this, this is the code that I have. There seems to be additional syntax errors in your code that is causing the other failures, but this is why $$type[] is giving you that error.
class debug {
public static $messages = array();
public static $errors = array();
public static $all = array(); // includes both of above
private static $types = array('messages','errors');
public static function add($type, $message) {
self::${$type}[] = $message;
self::$all[] = $text;
}
}
debug::add('messages', "Regular Message");
debug::add('errors', "Error Message");
print_r(debug::$messages);
print_r(debug::$errors);
And this is the output that I get
Array
(
[0] => Regular Message
)
Array
(
[0] => Error Message
)
2 Errors
A. if(!in_array($type,self::$types) ) { not properly closed .. you used ) insted of } at the end
B. self::$all[] = $text; $text not defined anywhere in the script
Try
class Debug {
private static $errors = array ();
private static $types = array (
'messages',
'errors'
);
public static function add($type, $message) {
if (! in_array ( $type, self::$types )) {
return false;
}
self::$errors [$type][] = $message; // results in error (see below)
}
public static function get($type = null) {
if (! in_array ( $type, self::$types ) && $type !== null) {
return false;
}
return ($type === null) ? self::$errors : self::$errors [$type] ;
}
}
debug::add ( 'errors', 'Error in ' . __FILE__ . ' on line ' . __LINE__ );
debug::add ( 'messages', 'Error in ' . __FILE__ . ' on line ' . __LINE__ );
var_dump(debug::get());
var_dump(debug::get("messages"));
I have a question regarding loops within an email template. My current email library gets passed an array of data and a template(.html) to search and replace. This works fine if I just need to replace any element wrapped in a square bracket [variable] . My library however can not deal with arrays of data(looping) and I need a more elegant solution than the ugly approach below
Cheers.
Email Library
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
require_once('phpmailer/phpmailer.php');
class Mailer{
protected static $mailer;
protected static $CI;
public function __construct()
{
self::$mailer = new PHPMailer();
self::$CI =& get_instance();
self::$CI->load->helper('file');
}
/**
*
* #param type $data
* #param type $template
* #return type
*/
public static function prepIt($data, $template)
{
$callback = function ($matches) use ($data){
return ( isset($data[$matches[1]]) )
? $data[$matches[1]]
: $matches[0];
};
return preg_replace_callback(
'/\[(.*?)\]/',
$callback,
read_file(EMAIL_TEMPLATES . $template));
}
/**
*
* #param type $data
* #param type $template
* #param type $to
* #param type $subject
* #param type $prep
* #return type
*/
public static function sendIt($data, $template='', $to, $subject, $prep=false)
{
self::$mailer->CharSet = 'utf-8';
if(self::$CI->config->item('email_smtp') === TRUE){
self::$mailer->SMTPSecure = "ssl";
self::$mailer->Host= self::$CI->config->item('email_host');
self::$mailer->Port= self::$CI->config->item('email_port');
self::$mailer->Username = self::$CI->config->item('email_user');
self::$mailer->Password = self::$CI->config->item('email_passw');
self::$mailer->SMTPKeepAlive = true;
self::$mailer->Mailer = "smtp";
self::$mailer->IsSMTP();
self::$mailer->SMTPAuth = true;
self::$mailer->SMTPDebug = 0;
}
if($prep)
{
self::$mailer->Body = self::prepIt($data, $template);
}
else
{
self::$mailer->Body = $data;
}
self::$mailer->IsHTML(true);
self::$mailer->Subject = $subject;
self::$mailer->AddAddress($to);
self::$mailer->FromName = self::$CI->config->item('email_from');
self::$mailer->From = self::$CI->config->item('email_primary');
try{
if(self::$mailer->Send()){
return true;
}else{
throw new phpmailerException(self::$mailer->ErrorInfo);
}
}catch(phpmailerException $e){
log_message('error', $e->getMessage());
}
}
return false;
}
Ugly Approach for non-defined templates
Note: sorry about poor formating here...
Instead of using a pre-made template, I have to pass a template on the fly so I can run a foreach loop with the data
if ($order->update_attributes($update_order)) {
$output ='<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/><title>Reciept</title><style type="text/css">#outlook a{padding:0;}
body{width:100%!important;}.ReadMsgBody{width:100%;}.ExternalClass{width:100%;}emails at full width*/body{-webkit-text-size-adjust:none;-ms-text-size-adjust:none;}
body{margin:0;padding:0;font:normal 14px tahoma,sans-serif;color:#515151;line-height:1.6em;}
img{height:auto;line-height:100%;outline:none;text-decoration:none;}
a img{border:none;}#backgroundTable{margin:0;padding:0;width:100%!important;}
p{margin-bottom:18px;line-height:1.6;color:#767676;}
h1,h2,h3,h4,h5,h6{color:black!important;line-height:100%!important;}
h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:blue!important;}
h1 a:active,h2 a:active,h3 a:active,h4 a:active,h5 a:active,h6 a:active{color:red!important;}
h1 a:visited,h2 a:visited,h3 a:visited,h4 a:visited,h5 a:visited,h6 a:visited{color:purple!important;}
table td{border-collapse:collapse;}
table th{text-align:left;padding:25px;}.yshortcuts,.yshortcuts a,.yshortcuts a:link,.yshortcuts a:visited,.yshortcuts a:hover,.yshortcuts a span{color:black;text-decoration:none!important;border-bottom:none!important;background:none!important;}
table#product{border-spacing:0;width:100%;}
table#product th{padding:8px;}
table#product td{padding:8px;border-bottom:1px solid#b1b1b1;}</style></head><body><table width="100%" style="background:#e3e3e3;text-align:center;padding:10px;width:100%;"cellpadding="0"cellspacing="0"border="0"id="backgroundTable"><tr><td><table cellpadding="0"cellspacing="0"border="0"width="650"style="text-align:left;padding:8px;background:#ffffff;border:1px solid #b1b1b1;"><thead><tr><th style="text-align:left;font-size:30px;padding:0;">Philip Kavanagh</th><th style="text-align:right;"><img src="http://localhost/crack_ie/assets/front/img/logo.png"alt=""/></th></tr></thead><tbody><tr><td colspan="2"><h2>Reciept</h2><p>Thank you for your recent purchase(s)from the store.<br>The Order has been proccessed by paypal successfully!</p></td></tr><tr><td colspan="2"><h3>Purchase Information</h3><p>Below you will find links to your digital downloads</p></td></tr><tr><td colspan="2"><table class="product"id="product"><thead><tr><td> </td><td>Title</td><td>Price</td><td>Download</td></tr></thead><tbody>';
foreach ($email_data as $out) {
$output .= '
<tr><td><img src="'.site_url(MEDIA . 'products/' . $out['img']).'" alt=""/></td><td>'.$out['title'].'</td><td>€'.$out['price'].'</td><td>Download</td></tr>
';
}
$output .= '
</tbody></table></td></tr><tr><td style="width:70%;"> </td><td style="width:30%;text-align:right;"><table style="text-align:right;border-spacing:0;"><tbody><tr><td style="width:100%;padding:5px;">Order#</td><td style="margin-left:30px;"><strong>7782tgh5</strong></td></tr><tr><td style="width:100%;padding:5px;">Items</td><td style="margin-left:30px;">'.$email_additional['items'].'</td></tr><tr><td>Tax</td><td>€0.00</td></tr><tr style="background:#d53015;color:#fafafa;width:100%;"><td>Total Amount</td><td style="font-size: 30px; padding: 8px;">€'.$email_additional['total'].'</td></tr></tbody></table></td></tr></tbody></table></td></tr></table></body></html>
';
if (Mailer::sendIt($output, '', $user->email, 'Purchase Confirmation: #' . $order->order_sku . '', false)) {
return true;
}
Edit: Answer Thanks to landons,
if ($order->update_attributes($update_order)) {
$output = $this->load->view('orders/email', array(
'data' => $somedata
), true);
if (Mailer::sendIt($output, '', $user->email, 'Purchase Confirmation: #' . $order->order_sku . '', false)) {
return true;
}
}
Have you considered simply passing data to a view (and returning the content, rather than displaying it)?