Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
Before:
Code:
$users = new User();
$users->where_related('group', 'name', 'Administrator')->get();
// Loop over all administrators
foreach($users->all as $u) {
    // do stuff
}

After:
Code:
$users = new User();
$users->where_related('group', 'name', 'Administrator')->get();
// Loop over all administrators
foreach($users as $u) { // <--- This line here!
    // do stuff
}

As you can see, it's a little easier to read, and one less "gotchya" type of mistake. It's especially nice with the 1.4.0 ability to seamlessly use (standard) plural relationship names:
Code:
// assume we know the group ID we want:
$group = new Group($group_id);
$group->users->get();
foreach($group->users as $u) {
    // do stuff
}

One caveat:
This completely breaks the (rarely-used) ability to do this:
Code:
foreach($user as $k => $f) {
    echo("user->$k = $f\n");
}

If I find that this is breaking a lot of existing code, I might pull it. If it only breaks a little, I have a workaround. If it doesn't break any, I'm leaving it as is.

[eluser]PoetaWD[/eluser]
[quote author="OverZealous" date="1249720366"]Before:
Code:
$users = new User();
$users->where_related('group', 'name', 'Administrator')->get();
// Loop over all administrators
foreach($users->all as $u) {
    // do stuff
}

After:
Code:
$users = new User();
$users->where_related('group', 'name', 'Administrator')->get();
// Loop over all administrators
foreach($users as $u) { // <--- This line here!
    // do stuff
}

As you can see, it's a little easier to read, and one less "gotchya" type of mistake. It's especially nice with the 1.4.0 ability to seamlessly use (standard) plural relationship names:
Code:
// assume we know the group ID we want:
$group = new Group($group_id);
$group->users->get();
foreach($group->users as $u) {
    // do stuff
}

One caveat:
This completely breaks the (rarely-used) ability to do this:
Code:
foreach($user as $k => $f) {
    echo("user->$k = $f\n");
}

If I find that this is breaking a lot of existing code, I might pull it. If it only breaks a little, I have a workaround. If it doesn't break any, I'm leaving it as is.[/quote]

Thank you man !!

Great stuff !!! One less detail to get us stucked !

Big Grin

[eluser]superflausch[/eluser]
Hi there,

I have a problem with my login script (which is based on the dmz example included in the download) as well as with the example itself, if I use it directly.

The problem:
It's always possible to login with a blank password field (in my code as well as in the example). A wrong password (with at least one character) doesn't work, the correct one works fine to login.

Maybe there should be an additional check if the password value is empty, or the validation doesn't work as it should or maybe I'm overlooking something else.

Would appreciate some hints. Smile I'm going crazy right now.

Thanks.

[eluser]Bnoe[/eluser]
i have problem to load a related table. example
table grade
- id
- grade_name

table school
-id
-grade_id


i create 2 model

Code:
class grade_model extends DataMapper
{
    var $model = 'grade_model';
    var $table = 'grade';
    
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

class school_model extends DataMapper
{
    var $model = 'school_model';
    var $table = 'school';
    var $has_one = array('grade_model');

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

is my code correct? can we add some class suffix like that? how can i display my data using join?

[eluser]OverZealous[/eluser]
[quote author="superflausch" date="1249846760"]It's always possible to login with a blank password field[/quote]

You know, this has come up before. I finally did some research, instead of my usual recommendation (manually check for empty passwords). The solution, it turns out, was to change a long-standing piece of code (since stensi managed this) in _to_array().

Anyway, I fixed it, and since it is fairly important, I quickly updated DMZ.

DataMapper OverZealous Edition 1.4.3 Update

Quote:Version 1.4.3: This update includes a bugfix when using validate->get.

Quote:Download the Latest Version Here

View the change log and the upgrade process
Having issues? Please look through the Troubleshooting Guide & FAQs
View the Complete Manual

[eluser]OverZealous[/eluser]
[quote author="Bnoe" date="1249849897"]is my code correct? can we add some class suffix like that? how can i display my data using join?[/quote]

Your code is not correct, because you have not specified the relationship from grade_model->school_model.

DMZ expects fairly strict table names. You really should follow the recommendations in the guide, using plural names for your tables, singular names for your models. If you have errors when not using these rules, they are most likely the cause.

If you are having trouble understanding how to use DMZ, the manual provides a lot of well-formatted, fairly clear examples. You really need to read through the entire General Topics group of pages.

[eluser]superflausch[/eluser]
[quote author="OverZealous" date="1249860974"]
You know, this has come up before. I finally did some research, instead of my usual recommendation (manually check for empty passwords). The solution, it turns out, was to change a long-standing piece of code (since stensi managed this) in _to_array().

Anyway, I fixed it, and since it is fairly important, I quickly updated DMZ.
[/quote]

I may overlooked those posts. Thank you for the new release and the quick answer.

Cheers.

[eluser]OverZealous[/eluser]
I want to notify everyone of a small problem with the new validate-get method:

Before, the method would only query on non-empty() fields. This meant that an empty password would be simply be ignored, which was the original issue. (This didn't affect username, because you need at least username to look up the user.)

So I changed that to only query non-NULL fields. This eliminated the empty field issue. It did, however, create an entirely new issue: If you (like me) use the trim pre-processing rule before the required rule, a NULL field will be converted into '' (empty string), due to the way the trim method works.

Therefore, the logins on my application failed.

My proposed solution is to add a _trim rule directly to DMZ, that ignores empty fields. This seems to work very well. I don't want to implement it until I have had more time to test, though.

If you are having trouble with 1.4.3, Add this to either libraries/datamapper.php or any class that uses required, trim, and gets looked up with validate->get:
Code:
/**
* Trim
* Custom trim rule that ignores NULL values
*
* @access    public
* @param    string
* @return    bool
*/    
function _trim($field) {
    if( ! empty($this->{$field})) {
        $this->{$field} = trim($this->{$field});
    }
}

[eluser]Bnoe[/eluser]
hmm.. it will be difficult touse dmz on non english language or we adopt non english database. any suggestion?

[eluser]OverZealous[/eluser]
[quote author="Bnoe" date="1249886684"]hmm.. it will be difficult touse dmz on non english language or we adopt non english database. any suggestion?[/quote]
Many people use it with non-English systems. There is no language database, DMZ just uses the inflector helper to convert the model or table name if they are not provided.

If you don't use it with English, you can still specify the table name in your language. My comment was that you should stick with the recommended model/table naming scheme. Unless you have a very good reason to avoid it (usually legacy databases), it makes it easier for me (and other DMZ users) to support.

There is only one location in the current DMZ where the inflector code is used without an alternate option: and that is when naming many-to-many self-relationship join tables (scroll down to Self Relationships). In this case, to ensure unique relationships, the table name is generated using plural($this->model) and plural($other->model), according to the rules linked above.

So, unless you plan to use many-to-many self-relationships, you can always safely override $model and $table to be whatever you like. You are also free to write / provide your own version of inflector helper. Just replace the inflector_helper.php that comes with DMZ.

(You also lose the ability to reference relationships using the plural form, such as $user->groups. But that doesn't break anything, just code readability.)




Theme © iAndrew 2016 - Forum software by © MyBB