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

[eluser]emorling[/eluser]
Quote:I don’t know if you still need the information, but there is nothing I know of that can cause CI to reload the same function, EXCEPT if you are accidentally calling $this->{controller_method}.

[SNIP]

That would call the controller method a second time. And because it isn’t getting the $id the second time, it won’t fall into a recursive loop.

This is driving me nuts. Smile

I run this.

Quote:function dosell($char_id, $item_id){
$this->output->enable_profiler(TRUE);

$char = new Character(); $char->get_by_id($char_id);
$item = new Item(); $item->get_by_id($item_id);
if(!$item->exists()){
echo("item does not exist");
return;
}
$item->delete();
echo("item exist");
}

Like this I get output "item does not exist".

If I comment the line $item->delete() I get "item exist".

My conclusion is that somehow the controller method is called twice. First it exists, and is deleted, and then it enters a second time and does not exist.

How can I debug further? Is there a debugger for CI? If it is being called a second time, how can I kill it the first time around? I tried using "die" but that didn't help.

This is my Item model. As you can see it has two hasOne relationships. I don't know if they can cause any trouble?

Quote:class Item extends DataMapper {

var $has_one = array('itemtemplate','character');

var $validation = array(
'name' => array(
'label' => 'name',
'rules' => array('required', 'trim', 'alpha_space', 'min_length' => 3)),
'itemtemplate' => array(
'label' => 'itemtemplate'
),
'character' => array(
'label' => 'character'
)
);

var $form_fields = array(
'id', // Hidden id field
'name', // name field
'itemtemplate',
'character'
);

function __toString(){
return empty($this->name) ? '«New Item»' : $this->name;
}
}

[eluser]emorling[/eluser]
OK, This is an update. I have now read up on the debugger in CI.

This is the controller I run.

Code:
function dosell($char_id, $item_id){
        $this->output->enable_profiler(TRUE);    
            
        log_message('debug', "STARTUP DOSELL($char_id, $item_id)");
        
        $char = new Character(); $char->get_by_id($char_id);
        $item = new Item(); $item->get_by_id($item_id);
        if(!$item->exists()){
            log_message('debug', "ITEM DOES NOT EXIST");
            die("item does not exists $char_id  $item_id");
        }        
                log_message('debug', "ITEM DOES EXIST");
        $item->delete();        
        die("item  exist");            
    }

And this is the LOG:

Quote:DEBUG - 2009-09-17 19:43:38 --> Config Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Hooks Class Initialized
DEBUG - 2009-09-17 19:43:38 --> URI Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Router Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Output Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Input Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Global POST and COOKIE data sanitized
DEBUG - 2009-09-17 19:43:38 --> Language Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Loader Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: url_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: utilities_helper
DEBUG - 2009-09-17 19:43:38 --> Database Driver Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/datamapper_lang.php
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: inflector_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: security_helper
DEBUG - 2009-09-17 19:43:38 --> Config file loaded: config/datamapper.php
DEBUG - 2009-09-17 19:43:38 --> Session Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: string_helper
DEBUG - 2009-09-17 19:43:38 --> A session cookie was not found.
DEBUG - 2009-09-17 19:43:38 --> Session routines successfully run
DEBUG - 2009-09-17 19:43:38 --> Controller Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Session class already loaded. Second attempt ignored.
DEBUG - 2009-09-17 19:43:38 --> Model Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: cookie_helper
DEBUG - 2009-09-17 19:43:38 --> STARTUP DOSELL(25, 459)
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: form_helper
DEBUG - 2009-09-17 19:43:38 --> Form Validation Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/form_validation_lang.php
DEBUG - 2009-09-17 19:43:38 --> ITEM DOES EXIST
DEBUG - 2009-09-17 19:43:38 --> Config Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Hooks Class Initialized
DEBUG - 2009-09-17 19:43:38 --> URI Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Router Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Output Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Input Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Global POST and COOKIE data sanitized
DEBUG - 2009-09-17 19:43:38 --> Language Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Loader Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: url_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: utilities_helper
DEBUG - 2009-09-17 19:43:38 --> Database Driver Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/datamapper_lang.php
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: inflector_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: security_helper
DEBUG - 2009-09-17 19:43:38 --> Config file loaded: config/datamapper.php
DEBUG - 2009-09-17 19:43:38 --> Session Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: string_helper
DEBUG - 2009-09-17 19:43:38 --> Session routines successfully run
DEBUG - 2009-09-17 19:43:38 --> Controller Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Session class already loaded. Second attempt ignored.
DEBUG - 2009-09-17 19:43:38 --> Model Class Initialized
DEBUG - 2009-09-17 19:43:38 --> STARTUP DOSELL(25, 459)
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: form_helper
DEBUG - 2009-09-17 19:43:38 --> Form Validation Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/form_validation_lang.php
DEBUG - 2009-09-17 19:43:38 --> ITEM DOES NOT EXIST

See the bolded items above. This confirms that the controller is run twice. It has to do with the row item->delete(), Any ideas?

[eluser]OverZealous[/eluser]
@emorling
Did you name a controller the same name as a model? You can't do that. This isn't a DMZ issue, because DMZ doesn't call controllers ever.

[eluser]OverZealous[/eluser]
[quote author="Daniel H" date="1253224385"]Is it at all possible to load all an object's related 'has one' objects on an ad hoc basis, instead of specifying it in the config?[/quote]

Yes, you call get() on each of the objects you want to load. :-)

If you have a lot of them, throw'em in a function on the model itself. If you want to load them when you run a query, make a custom getter that looks like this:
Code:
function get_autoload($limit = '', $start = '') {
    $this->get($limit, $start);
    $this->load_has_ones();
    foreach($this->all as $item) {
        $item->load_has_ones();
    }
}
function load_has_ones() {
    foreach($this->has_one as $key => $v) {
        $this->{$key}->get();
    }
}

// Usage:
$object->where(whatever)->get_autoload();

You really should load objects manually, anyway, otherwise you'll end up loading unnecessary information all the time.

I also saw your previous comment a while ago, but I forgot about it. The short version is that I would assume there either is a bug in HTMLForm or Array, or your models are misconfigured.

I don't have time right now to work on the extensions, but if you feel like debugging it some more, I'll happily apply a fix.

[eluser]emorling[/eluser]
[quote author="OverZealous" date="1253240621"]@emorling
Did you name a controller the same name as a model? You can't do that. This isn't a DMZ issue, because DMZ doesn't call controllers ever.[/quote]

Hm. None of my controllers have the same name as a model. Or do you see something I don't?

[eluser]OverZealous[/eluser]
[quote author="emorling" date="1253241698"]Hm. None of my controllers have the same name as a model. Or do you see something I don't?[/quote]
Nope, just throwing out suggestions. When I look at your log, I see two complete requests to the server. This means the browser is sending two requests. It has nothing to do with DMZ at all. (You wouldn't see the config and other class get re-initialized otherwise.)

[eluser]emorling[/eluser]
[quote author="OverZealous" date="1253241954"]When I look at your log, I see two complete requests to the server. This means the browser is sending two requests. It has nothing to do with DMZ at all. (You wouldn't see the config and other class get re-initialized otherwise.)[/quote]

Strange indeed. I am running Fiddler with Firefox and I see only one HTTP request, not two.

[eluser]emorling[/eluser]
Since this is not a DMZ problem I moved the discussion here:

http://ellislab.com/forums/viewthread/129445/

[eluser]Mirage[/eluser]
<b>Possible bug with created_field<b>

I have a table with the 'created' and 'updated' columns. DMZ (1.5.2) appears to be updating both columns with the current timestamp. Do I need to literally submit the created timestamp when updating existing records?

Code:
// Example sippet

$q = new Sae_Question();
$q->load_extension(array('htmlform','array'));
            
if ($_SERVER['REQUEST_METHOD']=='POST') {
    $seq=new Sae_Question();
     $seq->where('exam_id', $_POST['exam_id']);
     $seq->select_max('seq');
            
     $q->from_array($_POST);
     $q->seq=$seq->seq+1;
     $q->save();
     redirect('/sae/edit_question');
}

Thanks,
J

[eluser]OverZealous[/eluser]
[quote author="Mirage" date="1253244323"]Do I need to literally submit the created timestamp when updating existing records?[/quote]
No, created and updated are updated correctly, based on whether an object exists or not. You never need to set them manually.

If you set the column type to timestamp, however, some databases will automatically update those columns every time the row changes. Check out your database's documentation; it probably has nothing to do with DataMapper.




Theme © iAndrew 2016 - Forum software by © MyBB