[eluser]Unknown[/eluser]
Sorry if this could seem a stupid question but I'm not writing on here for lazyness because I searched a lot around but didn't manage to find a solution to a problem that I'm sure is so banal..
I'm using DMZ 1.4.0 and have and object in my model like this:
<?php
class Town extends DataMapper {
var $table = 'towns';
var $has_one = array(
'province' => array(
'class' => 'province'
)
);
var $validation = array(
array(
'field' => 'name',
'label' => 'Nome',
'rules' => array('required', 'trim', 'alpha_dash', 'max_length' => '255', 'unique')
)
);
function __construct()
{
parent::__construct();
}
function __toString () {
return $this->name;
}
}
/* End of file town.php */
/* Location: ./system/application/models/town.php */
Now I always get and error because the function __toString isn't returning a string value but this is due to the fact that the 'name' column isn't even selected from the database, in fact if I enable the profiler I notice that the query executed is:
SELECT `towns`.`id`
FROM (`towns`)
instead of something like:
SELECT `towns`.*
FROM (`towns`)
Now, how to fix this little thing ?
I'm doing this because I use the render_form method of the htmlform extension of DMZ, to automatically generate a form which fields reflect the validation array of an object. This object has a relation with the 'town' object so I need the render_form to automatically generate a dropdown with all the towns.
Please feel free to suggest me alternative ways if you think I'm approching badly to the problem, I've got a lot to learn and suggestions are very appreciated.
Thanks in advance to everyone
Francesco