Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]theprodigy[/eluser]
Ok, first things first:
Framework: CI 2.0
DMZ: 1.7.1

Code in question:
Code:
function _encrypt($field)
{
    $pass_key = "[removed]";

    // Don't encrypt an empty string
    if (!empty($this->{$field}))
    {
        $this->load->library('encrypt');
        $this->{$field} = $this->encrypt->encode($this->{$field}, $pass_key);
    }
}

I passed in the encrypt function to the validation for the password field.

The function is getting called, no problem there.

The issue is that I'm getting an error:
Quote:Fatal error: Call to a member function encode() on a non-object in /[path to application dir]/models/user.php on line 97
line 97:
Code:
$this->{$field} = $this->encrypt->encode($this->{$field}, $pass_key);
This is basically telling me that 'encrypt' is not an object, even though I am loading it in the line right above it.

Can someone please help me?

[eluser]OverZealous[/eluser]
@theprodigy

DMZ models are not CodeIgniter models - they do not get libraries set on them. You'll need to access the library directly, for example, via:
Code:
$CI = get_instance();
$CI->encrypt->...

[eluser]theprodigy[/eluser]
Thanks, it works now.

I could have sworn I read somewhere that DMZ uses CI's Active Record. That made me think that it already had an instance of CI.

Oh well, you live and learn ;-)

[eluser]WanWizard[/eluser]
@theprodigy:

DMZ objects aren't extended from a CI controller, so you can't access CI via $this:
Code:
$CI =& get_instance();
$this->{$field} = $CI->encrypt->encode($this->{$field}, $pass_key);
edit: Phil beat me to it...

[eluser]matthewwithanm[/eluser]
Has anybody ever successfully used set_value with DMZ?

From what I understand, CI has some issues with set_value and form_validation. The long and short of it is that, if you are using form_validation and want to use set_value, you have to set rules for your fields. I'm not sure if the CI guys consider this a bug or a feature, but it is the current behavior.

Datamapper triggers the issue by loading form_validation, but doesn't set its validation rules using set_rules.

This can be addressed by setting empty rules with form_validation->set_rules (for example, after the $label var is set in validate()) and calling form_validation->run() (e.g. at the end of the validate() method), though I'm not sure if this is the best approach.

I can certainly see an argument for this being a CI bug. However, it seems like Datamapper should at least work with the same restrictions that the framework establishes—namely, that a rule be set.

[eluser]WanWizard[/eluser]
set_value() is used to re-populate a form in a display -> submit -> validate -> display cycle.

For a Datamapper object, set_value() is of no use, Datamapper has no relation with the Form Validation library other than that it allows you to use validation methods in that library to validate Datamapper object properties.

[eluser]WanWizard[/eluser]
We're making good progress with the next version (at the moment we're targeting 1.8.0) of Datamapper.

You'll find the changelog here, the latest codebase can be found on Bitbucket, just click on "get source".

[eluser]theprodigy[/eluser]
I have a table in my database that has an auto-increment id primary key, and 3 foreign key fields. What is the best way to handle this? Do I just use it like a normal many-many join table, and set the third foreign key using
Code:
$object->set_join_field($model, $column, $value)

If I do that, I will have to set the third foreign key to allow null, right?

Is there a better way to handle it?

[eluser]WanWizard[/eluser]
In a normal many-to-many relationship, you will have a join table with only two foreign keys (one for each table), and the join table itself doesn't have a Datamapper model. Both foreign keys need to allow NULL. The join table has the name of both other tables, in alphabetical order.

If you add a third foreign key, you're basically creating a one-to-many from the join table to a third table. So you need a model for the join table, and define the relation. This foreign key also need to allow NULL.
You can use set_join_field(), and not treat this field as a foreign key in Datamapper context, but you still need the model to be able to access the relationship this third foreign key defines.

[eluser]theprodigy[/eluser]
ok, so to make sure I understand correctly, let's assume I have tables ones, twos, threes (with models one, two, three). I then have join tables of ones_twos, and ones_threes. Let's assume for this example, in ones_twos, I also have three_id (so that the table has id, one_id, two_id, and three_id).

Now, from your first explanation, I need to create a model for ones_twos, defining the relationship between ones_twos, and threes.

So, my model will look like?
Code:
class Ones_twos extends DataMapper {

    var $has_one = array();

    var $has_many = array('three');
    
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

Will this allow me to access the 'threes' the same way I will the 'twos' and 'ones', or will I need to explicitly call this model in order to get the 'threes'? Having a model like this, (how) does this affect the original relationship between the 'ones' and 'twos'?

Sorry for all the questions, still learning ;-)




Theme © iAndrew 2016 - Forum software by © MyBB