[eluser]Maurice Calhoun[/eluser]
[quote author="sophistry" date="1190711240"]ok maurice, more PHP4 migration problems maybe you can help me with. as you know i am trying to get PHP4 to work with this code. i've got the find functions working but i wanted to try the other techniques listed in the wiki. specifically this technique of combining columns for output:
EDIT... added entire code to make sure I wasn't leaving anything out.
Code:
// this is the Controller extended
// the p() function is a debugging function i use to print vars
<?php
class Addresses extends Controller {
var $Address;
function Addresses()
{
parent::Controller();
$Address =& $this->load->model('Address');
}
function index()
{
echo "Welcome to my address list!";
//$addresses = $this->Address->find(ALL);
$data = array('host_domain'=>'domain.com');
$addresses = $this->Address->find_and_limit_by(2,0,array($data));
//p($addresses);
foreach ($addresses as $obj)
{
//p($obj);
// addressing the objects from outside the class works
// no errors in this one
$full_email = ($obj->mailbox . '@' . $obj->host_domain);
// relying on a class function that uses $this-> doesn't work
// errors on every iteration except the first in this one
$full_email_too = $obj->emailaddress();
p($full_email); // prints all email addresses fine
p($full_email_too); // prints only the first and then stops
}
}
}
?>
// and the model
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Address extends ActiveRecord {
function Address()
{
parent::ActiveRecord();
$this->_class_name = strtolower(get_class($this));
$this->_table = 'address';
$this->_columns = $this->discover_table_columns();
}
// this kind of function is like a calculation field
function emailaddress()
{
return $this->mailbox . '@' . $this->host_domain;
}
}
?>
when i put that in my address model, php complains about undefined property:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: mailbox
Filename: models/address.php
Line Number: 19
so, i'm thinking it has to do with the different way that PHP4 handles "overloaded" class properties and somehow there isn't support for that in the PHP4 version of overloading. i tried implementing the __get and __set magic functions but to no avail - they just cause the rest of the class properties to vanish!
tell me, am i missing something obvious?[/quote]
Message: Undefined property: mailbox
To be able to use the $this->mailbox property in your Address model it has to be assign. I think that you can do this inside of your foreach loop in your controller like this
Code:
$this->Address->mailbox = $obj->mailbox;
I think this should work.