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

[eluser]WanWizard[/eluser]
I'll park this question for the moment if you don't mind, busy with some other stuff. But I'll set up a test with this table setup, and I'll let you know the result.

[eluser]theprodigy[/eluser]
Cool beans. I appreciate it.

[eluser]WanWizard[/eluser]
Ok, I've ran some tests.

I've created the tables "ones", "twoes" (this is what datamapper does by default!), "threes" and "ones_twoes":
Code:
The model One:
- has_one to one_two
- has_many to two and three

The model Two:
- has_many to one

The model Three:
- has_many to one and one_two

The model One_two:
- has_one to one, two and three

With this setup, I can do:
Code:
// simple one-to-many
$one = new One(1);
$one->three->get();

// access three via the relationship table
$one_two = new One_two(1);
$one_two->three->get();

// get the relationship directly
$one->one_two->get();

// get three via the one_two relationship table
$one->one_two->three->get();

So yes, you can use the three_id in the relationship table between one and two if you define one_two as a model with the proper relationship definitions.

Datamapper doesn't care how crazy you make it, al long as the relationships are defined properly, and the correct tables (and id fields) are there. You can even create a many to many between ones_twoes and fives_sixes with would create a relationship table called one_twoes_fives_sixes!

[eluser]DominixZ[/eluser]
@WanWizard I'm very appreciate. That you will continue this project. i tried your DataMapper in BitBucket and I found a bug in $object->delete

I have "Account" model and "Group" model that has many to many relationship

I use
$group->delete(); and then error is

Class a not found

I don't know why it bug and i switched back to 1.7.1 and then bug is gone.

=====
about "set_value()" DataMapper DMZ use form_validation to use rule that has in form_validation to validate but it doesn't set the rule so "set_value()" will not work but in my opinion i only want to pop data from post so I go to

"function &_get_validation_object()"

and then "return false;" in the beginning of function and then "set_value()" can pop $_POST data. because now We will validate when save not before save so I feel secure to not validate $_POST data cause I can xss_clean in DataMapper model.

Have fun with DataMapper DMZ Smile

P.S. I have a small helper project. I will rewrite form_helper to use for DataMapper DMZ and I will contribute back soon. See you guys.

[eluser]WanWizard[/eluser]
Can you be a bit more specific?

What is the exact error message? On which line? What does your models look like? What's the content of the objects when you call delete?

As to set_value: Datamapper doesn't use Form validation, it allows you to use the validation methods in the form validation library. set_value() is something related to $_POST, which has nothing to do with Datamapper.

[eluser]DominixZ[/eluser]
My PHP version is 5.0, Download DataMapper at BitBucket (10/11/2010) and problem is from
application/libraries/datamapper.php

Class a not found
Line Code Error : 1978
"$object = new $class();"

I investigated a little and i see it $properties['class'] return on "a" instead of "account" and $properties return "account" i don't know why this happen and then I start hard code "account" to that but still didn't work it return "Database Error" because my "account" model has been changed to "a" instead so Database cannot found it.

My "Account" Table
Picture

My "Group" Table
Picture

My "Accounts_Groups" Table
Picture

When I'm delete Group only has all data field fill but without any relationship with Account. (with Relationship also doesn't work)

======
Quote:As to set_value: Datamapper doesn’t use Form validation, it allows you to use the validation methods in the form validation library. set_value() is something related to $_POST, which has nothing to do with Datamapper.

The problem is DataMapper load "Form_validation" so in "set_value()" function you will see it will check if "Form_validation" is load and then use "Form_validation" prep instead of $_POST and default so that why people can't use "set_value()" cause DataMapper load them but not set the rule

when We use "set_value()" it check Form_validation is load then it return Form_validation object and pass argument to use Form_validation instead and no rule so doesn't work my fixed is close the way "set_value" function to get "object return" and i return ony "false" so then it will only use $_POST and default not use "Form_validation"

May be i bit confusing but explain why "set_value()" doesn't work with "DataMapper" Smile

[eluser]WanWizard[/eluser]
Check the server requirements: minumum PHP version for Datamapper is 5.1.2.
Someone managed to get it to work with 5.0.0 (see http://ellislab.com/forums/viewreply/728767/), but no guarantees.

I understand what you mean now with set_value(). Would you please report the issue at http://bitbucket.org/wanwizard/datamapper/issues, so it doesn't get lost? Add a link to this thread.
I'll see if I can come up with something.

[eluser]WanWizard[/eluser]
Quick fix:

Look in datamapper.php for the code that loads the form_validation library, and replace it by this:
Code:
if($name == 'form_validation')
{
    if ( ! isset($this->form_validation) )
    {
        $CI =& get_instance();
        if( ! isset($CI->form_validation))
        {
            $CI->load->library('form_validation');
            $this->lang->load('form_validation');
            unset($CI->load->_ci_classes['form_validation']);
        }
        $this->form_validation = $CI->form_validation;
    }
    return $this->form_validation;
}

Does this fix the problem?

[eluser]WanWizard[/eluser]
A new version of Datamapper ORM has just been committed to Bitbucket.
Just click on "get source" to download the lastest version.

This version introduces a new extension to work with nested sets (used to store tree structures in a database). Not all planned functionality is present yet, but it's very usable. You can find the manual page for this extension here.

You'll find the complete changelog here.

Note that this version has been tested with today's version of CI 2.0. Although still no guarantees, we haven't found any problem.

[eluser]theprodigy[/eluser]
Having a slight problem with get_rules.

When checking login, it works just fine. But when trying to output the password in a password input field, it's outputting the encrypted text, causing the field to act strange (closing the value attribute early, etc).

Model in question:
Code:
class User extends DataMapper {

    var $has_one = array('group');

    var $has_many = array('maillist','email','sent_email','signature');

    var $validation = array(
        'group_admin' => array(
            'rules' => array('xss_clean','trim','required'),
            'label' => 'Group Admin'
        ),
        'fname' => array(
            'rules' => array('xss_clean','trim','required', 'max_length' => 255),
            'label' => 'First Name'
        ),
        'lname' => array(
            'rules' => array('xss_clean','trim','required', 'max_length' => 255),
            'label' => 'Last Name'
        ),
        'username' => array(
            'rules' => array('xss_clean','trim','required', 'max_length' => 255),
            'label' => 'User Name'
        ),
        'password' => array(
            'rules' => array('xss_clean','trim','encrypt','required', 'max_length' => 255),
            'label' => 'Password',
            'get_rules' => array('decrypt')
        ),
        'email_address' => array(
            'rules' => array('xss_clean','trim','valid_email','required', 'max_length' => 255),
            'label' => 'Email'
        )
    );
    
    var $default_order_by = array('group_admin','fname', 'lname');
    
    // --------------------------------------------------------------------

    function __construct($id = NULL)
    {
        parent::__construct($id);

        $this->pass_key = "[removed]";
    }
    
    // --------------------------------------------------------------------
    // Custom Methods
    // --------------------------------------------------------------------
    
    public function check_login($username, $password)
    {
        $return = false;

        $user = new User();
        $user->where('username',$username)->get();

        if($user->password == $password)
        {
            $return = $user->id;
        }

        return $return;
    }
    
    // --------------------------------------------------------------------
    // Custom Validation Rules
    //   Add custom validation rules for this model here.
    // --------------------------------------------------------------------

    function _encrypt($field)
    {
        if (!empty($this->{$field}))
        {
            $CI = get_instance();
            $CI->load->library('encrypt');
            $this->{$field} = $CI->encrypt->encode($this->{$field}, $this->pass_key);
        }
    }

    function _decrypt($field)
    {
        if (!empty($this->{$field}))
        {
            $CI = get_instance();
            $CI->load->library('encrypt');
            $this->{$field} = $CI->encrypt->decode($this->{$field}, $this->pass_key);
        }
    }
}

In the controller:
Code:
class Profile extends MY_Controller {

    public function  __construct() {
        parent::__construct();
    }

    //[other functions]

    public function manage()
    {
        $user = new User($this->session->userdata('user_id'));

        if($this->input->post('submit'))
        {
            
            $user->fname = $this->input->post('first_name');
            $user->lname = $this->input->post('last_name');
            $user->email_address = $this->input->post('email');
            
            if($user->save())
            {
                redirect('profile');
            }
        }

        $user->group->get();
        $lists = array();
        foreach($user->maillist->get() as $list)
        {
            $scope = ($list->private == 1)?"private":"public";
            $lists[] = $list->name . ' (' . $scope . ')';
        }

        if(count($lists) == 0)
        {
            $lists[] = '<em>none</em>';
        }
        $this->data['lists'] = $lists;
        $this->data['user'] = $user;
    }
}

In the view:
Code:
//[other design stuff]
<div class="box">
    <h2>Manage Your Profile</h2>
    &lt;?php
    foreach ($user->error->all as $e)
    {
        echo '<div class="error">'.$e . '</div>';
    }
    ?&gt;
    &lt;?php echo form_open('profile/manage','',array('user_id'=>$user->id)); ?&gt;
        //[Other fields]
        <p>
            <label for="password">Password</label>
            &lt;?php $pass = $user->password; ?&gt;
            &lt;input type="password" name="password" value="&lt;?php echo $pass; ?&gt;" /&gt; // <--- This is where the issue is.
        </p>
        //[Other fields]
<p>
            &lt;input type="submit" name="submit" value="Submit" /&gt;
            &lt;input type="reset" name="reset" value="Reset" /&gt;
            <br /><br />
            &lt;input type="button" name="cancel"&gt;
        </p>
    &lt;/form&gt;
</div>
*(I’m using Jamie Rumbelow’s MY_Controller—in case that matters somehow)




Theme © iAndrew 2016 - Forum software by © MyBB