EllisLab text mark
Advanced Search
2 of 32
2
   
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)
Posted: 07 December 2009 02:47 AM   [ # 21 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-29
344 posts

yeah im still at the 1.5.3 so im reading the 1.6.0 update lol

I know but its still the processes of learning and using the new functionality (when needed)

edit: btw I normaly do read the change log to see what you did lol

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger :: DB Configs

 
Posted: 07 December 2009 02:50 AM   [ # 22 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

I figured you did.  I just like to ... um ... reinforce the existence of certain aspects of the docs. grin

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 07 December 2009 02:58 AM   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-29
344 posts
OverZealous - 07 December 2009 07:50 AM

I figured you did.  I just like to ... um ... reinforce the existence of certain aspects of the docs. grin

Yeah I think after the second time you “um ... reinforced the existence” of them I’ve started going there first to find my answers then coming here!

But yeah I agree, I’ve noticed a lot of well documented/repetitive questions that are easily answered in the technical issues, or some main page of the docs. So reinforcement is good!

NOTE: I am not saying anyone is lazy/dumb/stupid etc… for asking questions even if they are answered in the docs. I know we all at some points just space and don’t see something right in front of us. Or just need more clarification. (in the later instance provide the knowledge that you know whats going on tho. It helps us save time in helping you.)

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger :: DB Configs

 
Posted: 07 December 2009 10:01 AM   [ # 24 ]   [ Rating: 0 ]
Joined: 2009-11-06
7 posts

Hello
I have been using this Datamapper for a few weeks and its works perfect. Thank you very much.

But i come up with a problem.

I have a loginform in the right sidebar.
And in the main area i have a registerform.

When I fill in wrong data in the registerform I get two “There was an error saving the form.” Both in the main area and in the sidebar.

Both forms are rendered from a user model. Is this the problem ?
I tried using custom templates, like this

echo $user->render_form(array('username' 'password' => 'password'),'login/check_login',array('save_button' => 'Log in'),'dmz_htmlform/login_form','dmz_htmlform/login_row','dmz_htmlform/login_section'); 

But I have no luck,

 
Posted: 07 December 2009 05:54 PM   [ # 25 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-10
778 posts

Say, what’s a good way of dealing with validation where a field is only used on creating a new object - but is otherwise never used?

I want to use a password_confirm field to control account creation, but obviously beyond account creation it is never used. I’m probably just going to hack a custom validation rule that checks $this->id, or use a bit of controller logic - but is there a better way to handle this that is eluding me?

 Signature 

CreativeHalls Web Design and Printing
A few of my projects:
OurGulfCoast Property Management and Vacation Rental (ASP/.NET)
BukuBux - Money Saving Coupons and Gift Certificates (CodeIgniter, LAMP/MySQL)
Rentals800.com - Find a place to rent (CodeIgniter, LAMP/MySQL)
bdh (dot) hall (at) gmail (dotcom)

 
Posted: 07 December 2009 06:26 PM   [ # 26 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts
silvergear99 - 07 December 2009 03:01 PM

Both forms are rendered from a user model. Is this the problem ?

If they are the same user model, then yes, because the validation is done on the object itself, and the errors are tracked on the object.

I assume that after the user attempts to login with the sidebar, they are redirected to the “normal” login page, correct?  If so, simply create a new, empty User object to use for rendering the sidebar, or, alternatively, create an empty user for the registration page (since logically the user is new).

But the error messages shouldn’t be shared across two different user objects.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 07 December 2009 06:38 PM   [ # 27 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts
BrianDHall - 07 December 2009 10:54 PM

I want to use a password_confirm field to control account creation, but obviously beyond account creation it is never used.

In this specific example, you don’t need to make it complicated.  If you use matches and required on a password_confirm field, DMZ will automatically fill in the virtual password_confirm field when loading an existing object.  The only time you need to do something special is when programmatically changing the password (like a generated password); then you’ll need to set both.

Besides, can’t the user change the password at a later date?  They’ll need a password_confirm then, too.

—————

But, if you still want to create an only-required-when-new field, you’ll probably need to do this:

1) Create a custom required method on your object, that has a specific check for the confirmation field:

function required($field{
    
if($field == 'password_confirm' && $this->exists()) {
        
// You could try setting password_confirm here
        // This may not work if you are properly encrypting the password!
        // $this->password_confirm = $this->password;
        
return TRUE;
    
else {
        
return parent::required($field);
    
}

2) For any other validation rules used on that field, you’ll probably need to override them like above.  (You might even want to add a method for doing the field/exists check, so you aren’t copying and pasting code all over.)

—————

I might add (yet another) validation rule required_when_new that handles this internally.  It’s an easy addition.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 08 December 2009 01:35 AM   [ # 28 ]   [ Rating: 0 ]
Joined: 2009-05-30
17 posts

I apologize if this is covered in the guide. I didn’t find it, but maybe I wasn’t looking in the right place.

I’m wondering if there is a way to get the count of related items without going to the database.

So I have a user object that has a has_many relationship with an alias object. I get the collection of aliases by $user->alias->get(); But once I have that collection, it seems to me that I should be able to get the count of aliases by determining the number of records in the collection.

Is there a best practice way to accomplish this with DataMapper OverZealous and Codeigniter?

$user->alias->count() works, but goes to the database. If that’s the best way to get the data I need, that’s cool.

Thanks for your time & for the great library.

 
Posted: 08 December 2009 01:38 AM   [ # 29 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@someoneinomaha
Just use PHP!

$count count($user->alias->all); 

I’m pretty sure there are examples of this in the DB docs.

Update: Added this to the count documentation.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 10 December 2009 02:35 PM   [ # 30 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-10
778 posts

Pardon me if this is a silly question, but consider this:

$user->usergroup->get();

So you get the usergroup that the user belongs to - simple. But where the hell is the usergroup object?

If I do:

$usergroup = $user->usergroup;

...that works, and $usergroup is now my usergroup object. When I use my debugger to look into the $user object, there is no sign of usergroup anywhere in it, nor in any other variable I can seem to locate.

If I want to peek into the structure of such a related object, do I need to assign it to a variable before I’ll be able to see it, or am I just missing where it might be hiding?

EDIT: The point of this is mainly for debugging purposes, and technically I’m trying to hand off one of my Datamapper objects in a way friendly to the CI Template parser, since it isn’t capable of understanding object properties or array elements. So I want to use my debugger to peek and make sure I’m doing this in the most logical way, and it’s hard when the object in question can’t be found.

 Signature 

CreativeHalls Web Design and Printing
A few of my projects:
OurGulfCoast Property Management and Vacation Rental (ASP/.NET)
BukuBux - Money Saving Coupons and Gift Certificates (CodeIgniter, LAMP/MySQL)
Rentals800.com - Find a place to rent (CodeIgniter, LAMP/MySQL)
bdh (dot) hall (at) gmail (dotcom)

 
Posted: 10 December 2009 02:40 PM   [ # 31 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@BrianDHall

All of the related objects in DMZ are created via PHP magic methods.  Actually, a lot of the stuff is magically generated.  This has several very important benefits:

1) You don’t waste memory and time creating unused objects.
2) You avoid infinite recursion ($user->usergroup->user->usergroup->user->...)
3) Autoloading is more intelligent - the objects are only auto-loaded the first time you access them.

The side effect is that many of the properties of a DMZ model are not visible to debuggers until the first time they are used.

Also, I haven’t actually gotten a proper PHP debugger set up yet (I know - shameful), so I don’t know if there are limitations [in the debugger].

Edited last sentence.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 10 December 2009 03:00 PM   [ # 32 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-10
778 posts

Aha, thanks Phil - that makes sense now.

For those interested I worked out how to make it work with a single function either in the datamapper object, or you can make it into an extension to use in all of them if you are so inclined:

Extremely easy:

function get_parsable_array()
    
{
        $i 
0;
        foreach (
$this->all as $res)
        
{
            
foreach ($res->stored as $key => $value)
            
{
                $return[$i][$key] 
$value;
            
}
            $i
++;
        
}

        
return $return;
    

So now you can easily do something like this:

$forum = new Forum(1);

$forum->threads->get();

$threads $forum->threads->get_parsable_array();

$this->parser->parse->('view_here', array ('threads' => $threads)) 

And then you can do something like this in the view:

{threads}
{title}
last post {last_post_time}
{
/threads} 

Playing with the template class to minimize code mixing with HTML - purely because I hate all the <? ?> crap, reminds me of spaghetti code too much.


EDIT: I’ve noticed something highly annoying to me - while the parser does understand the previous code in a sort of foreach style with less coding, you can’t follow it along with php code mixed in when necessary. So you can’t stick in an if() to, say, turn a flag of whether or not a post is new into something other than its raw variable inside the {tag}{/tag} execution.

Seems like trading a case of dry scalp for crabs. No thanks.

LOL

 Signature 

CreativeHalls Web Design and Printing
A few of my projects:
OurGulfCoast Property Management and Vacation Rental (ASP/.NET)
BukuBux - Money Saving Coupons and Gift Certificates (CodeIgniter, LAMP/MySQL)
Rentals800.com - Find a place to rent (CodeIgniter, LAMP/MySQL)
bdh (dot) hall (at) gmail (dotcom)

 
Posted: 10 December 2009 09:44 PM   [ # 33 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-29
344 posts

Hey Pill having some issues with the extensions.

$n = new Note();
// It is highly recommended you load the note before saving.
$n->get_by_id($this->input->post('id'));

$related $n->from_array($_POST, array('message''date''category'));
// $related includes any new categories that need to be saved.  At this point, $n may have had some old categories deleted.

// add a related editor
$related['editor'$logged_in_user;

// save with the related objects
if($n->save($related))
{
    
// redirect after save

For some reason the $related is not being set as if the from_array is not passing off the data when set to a variable. The other method where I save with from_array($_POST,’‘,TRUE); works tho.

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger :: DB Configs

 
Posted: 10 December 2009 09:51 PM   [ # 34 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@tdktank59
That has nothing to do with the extensions.  That’s a normal related save.  You probably have a misconfiguration in your relationships, or $logged_in_user is invalid.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 10 December 2009 09:58 PM   [ # 35 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-29
344 posts
OverZealous - 11 December 2009 02:51 AM

@tdktank59
That has nothing to do with the extensions.  That’s a normal related save.  You probably have a misconfiguration in your relationships, or $logged_in_user is invalid.

That was your demo
http://www.overzealous.com/dmz/pages/extensions/array.html

Heres what I am using and it dosnt work (following your examples btw)

$c = new Customer();
        
        if (
$_POST)
        
{        
            $rel 
$c->from_array($_POST, array(
                
'first_name',
                
'last_name',
                
'address',
                
'city',
                
'state',
                
'zip',
                
'country',
                
'phone_number'
            
));

            
$rel['custom_id''C'.random_string('alnum'11);
            if (
$c->save($rel))
            
{
                $this
->session->set_flashdata('success''The Customer has been created');
                
$this->session->set_flashdata('customer_id',$c->id);
                
redirect('customers');
            
}    
        }
        
        
echo $c->render_form(array(
                
'Customer' => 'section',
                
'first_name',
                
'last_name',
                
'address',
                
'city',
                
'state',
                
'zip',
                
'country',
                
'phone_number'
            
),
            
'customers/create',
            array(
                
'save_button' => 'Save',
                
'reset_button' => 'Clear'
            
)
        ); 


EDIT: Never Mind it works… My relations were screwed up since I hadnt setup one of the models yet.

 Signature 

421 Entertainment :: YAAS - Yet Another Authentication System :: Error Logger :: DB Configs

 
2 of 32
2