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

[eluser]12vunion[/eluser]
Has anybody had any luck using the htmlform extension and reCaptcha? I'm having a bit of trouble getting the two working together.

[eluser]OverZealous[/eluser]
I don't know anything about using reCaptcha, but I suggest making a custom type function for it.

Another option is to make a custom row template (next thing after the link above), and override the row template for that one item. You can put anything you want into a row template.

Edit: I forgot, you can also just output a string of text without any extra work! Smile

You'd think I'd know my own code better :lol:

[eluser]Alface[/eluser]
[quote author="OverZealous" date="1256955791"]@Alface
Edit: removed rude comment - sorry, I just got up.

Validation is automatically run when you call save. This has nothing to do with the transaction status. Every time you call save(), you must check the result, for every object.

If validation fails, the save will not go through. The whole point of using transactions is that you can safely save multiple items, and if the last one fails, the DB will rollback all of the changes. In fact, you have to do it this way, because DMZ expects "existing" items to exist in the database, even ones just saved.

Finally, the transaction status is only useful in explaining when the database itself has been unable to save. If the failure was in the validation of your DMZ model, the transaction status will be TRUE, because no save query was processed.

So, again, your code needs to look like this:
Code:
if($object->save()) {
    if($object2->save($object1)) {
        // etc
    } else {
        // etc
    }
} else {
    // fail
}

or like this
Code:
$success = $object->save();
$success = $success && $object2->save();

if(!$success) {
    // process $object->error and $object2->error
}
[/quote]


By default DMZ came with a form template than handle the list of erros like this:
Code:
<? if( ! empty($object->error->all)): ?>
<div class="error">
    <p>There was an error saving the form.</p>
    <ul>&lt;? foreach($object->error->all as $k => $err): ?&gt;
        <li>&lt;?= $err ?&gt;</li>
        &lt;? endforeach; ?&gt;
    </ul>
</div>
&lt;? endif; ?&gt;

And when I call it form the htmlform extension
Code:
&lt;?=$va->render_form($campos,$url)?&gt;


The question is, how can I unificate the list of erros of 2 objects?
Code:
$success = $object->save();
$success = $success && $object2->save();

if(!$success) {
    // process $object->error and $object2->error

    // if I repeat render_form(), I will have 2 forms..
    // and I would like to reuse the same form template
    // $object->render_form($fields,$url)
}

[eluser]tomdelonge[/eluser]
Nevermind, this has been solved (mediatemple gridserver has an incurable habit of reverting to php 4 without my permission... randomly. I've had this same sort of problem with them before. Oh well.

DMZ worked fine on localhost, but when i put it on the gridserver (mediatemple), I keep getting this error:
Code:
Parse error: syntax error, unexpected T_STRING, expecting '{' in /MY_DOMAIN_HERE/application/libraries/datamapper.php on line 20

[eluser]OverZealous[/eluser]
My guess is the file got corrupted when you uploaded it. Try deleting it off the server and re-uploading it.

Also, make sure the host is serving PHP 5 - DMZ will not work under PHP 4.

[eluser]The Mask[/eluser]
Can anybody please explain this?

$u = new User;

$x = $u->get_where( 'id < 4' );
$y = $u->get_where( 'id < 7' );

foreach ( $x as $z )
{
echo $z->id;
}

displays 123456??

Am I missing something here? How come it displays 4,5 & 6?

[eluser]OverZealous[/eluser]
[quote author="The Mask" date="1257257311"]Am I missing something here? How come it displays 4,5 & 6?[/quote]

Because you are working with objects. Therefore, $x and $y both refer to the same object, $u. (Technically, $u also refers to an object, User. You could re-assign $u without affecting $x or $y, which would still point to the original User.)

When you call $u->get_where('id < 7'), you overwrite the results of the previous query. If you want different result sets, you need to instantiate different objects.

Code:
$x = new User();
$x->get_where('id < 4');
$y = new User();
$y->get_where('id < 7');

Now $x and $y refer to different objects. It is not necessary to store the result of a get() (in any of its forms), except for convenience in the case of related child objects.

[eluser]The Mask[/eluser]
Many thanks for the swift reply OZ.

I must say I think this is very cool and just finding my way around it - you're doing a fantastic job, well done!

I have another question.

I thought I would be able to do this:
$u = new User(1);
echo $u->company->industry->name;

But to get this working, I had to do:
$u = new User(1);
$u->company->get();
$u->company->industry->get();
echo $u->company->industry->name;

Is there a better way to achieve this - thanks!

[eluser]OverZealous[/eluser]
[quote author="The Mask" date="1257273810"]
Is there a better way to achieve this - thanks![/quote]

There are several options. The first is to do it like this:

Code:
$u = new User(1);
echo $u->company->get()->industry->get()->name;

It's less verbose.

The second is to include the data you want in the first query, saving several trips to the DB:
Code:
$u = new User();
$u->include_related('company/industry', 'name')->get_by_id(1);
echo $u->company_industry_name;

The third is to enable auto_populate_has_one in the configuration, which will work more like you intended. Be warned, however, that auto_populate will cause your application to make queries that you may not have intended.

[eluser]The Mask[/eluser]
Awesome!
This really does rock!
Absolutely love it.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB