Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 30. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Simple Trigger Question

phpMyEdit Configuration     Simple Trigger Question
Odoslať novú tému   Odpovedať na tému    
 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-10 13:35
Návrat hore  Odpovedať s citátom     

I have this code right above the call to the class:

Kód:
$opts['triggers']['update']['before'] = 'categories.TUB.inc';


And have this in my 'categories.TUB.inc' file:
Kód:
<?php $newvals['modified'] = 'NOW()';
return true; ?>
.

I get 0000-00-00 after doing an update, or an insert. If I fill in the field on the update, I get the date I put in, so no overide is taking place.

I have tried many versions of this code. Any help would be appreciated.

Barry


Naposledy upravil k4mg dňa 2007-05-12 14:58, celkom upravené 1 krát

 
TomWitt     Založený: 30.08.2004   Príspevky: 5  
Príspevok Zaslal: 2007-05-10 15:40
Návrat hore  Odpovedať s citátom     

k4mg Napísal:
I have this code right above the call to the class:

Kód:
$opts['triggers']['update']['before'] = 'categories.TUB.inc';


And have this in my 'categories.TUB.inc' file:
Kód:
<?php $newvals['modified'] = '$NOW()';
return true; ?>
.

I get 0000-00-00 after doing an update, or an insert. If I fill in the field on the update, I get the date I put in, so no overide is taking place.

I have tried many versions of this code. Any help would be appreciated.

Barry


Hey Barry.

I was doing something similar and this seemed to work:
  1. In the table, I have a field, last_modified, defined as a datetime field.

  2. In my phpMyEdit script file, I have the trigger file definitions before the inclusion of the phpMyEdit class.

    Kód:
    //--------------------
    // Trigger definitions
    //--------------------
    //$opts['triggers']['update']['before'] = 'dk.tub.inc';
    //$opts['triggers']['insert']['before'] = 'dk.tib.inc';

    //--------------------
    // phpMyEdit call
    //--------------------
    // Now important call to phpMyEdit
    require_once 'phpMyEdit/phpMyEdit.class.php';
    new phpMyEdit($opts);


  3. Both trigger files (dk.tub.inc and dk.tib.inc) contain this same code
    Kód:
    <?php
    // set the last_modified modification date to this moment
    // using the PHP 'date' function to generate and format the date/time for this moment
    $newvals['last_modified'] = date("Y-m-d H:i:s");
    ?>


On any insert or update to this table using this phpMyEdit script, the field last_modified is successfully set to the current date/time.

This solution works

Option 2

However, there appears to be a much simpler way to do this without the need for triggers.

Using the 'sqlw' function, (and the options variability modifiers '|AC' to use this write sql function only when performing an A[dd] or a C[hange]), include some sql code to update the field with the current date/time.

Kód:
// uses the MySQL function 'now()' to generate the date/time during row add or change
$opts['fdd']['last_modified'] = array(
  'name'     => 'Last Modified',
  'select'   => 'T',
  'options'  => 'ACVPDLF',
  'sqlw|AC'  => 'now()',
  'maxlen'   => 19,
  'required' => false,
  'sort'     => true
);



Hope this helps.

-- Tom

 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-11 18:31
Návrat hore  Odpovedať s citátom     

Thanks, but I think your answer is just the same as my non-working attempt. I just can't figure out what is wrong. I did try date() vs. now() but it didn't help.

Barry

 
aeiche     Založený: 06.04.2007   Príspevky: 10  
Príspevok Zaslal: 2007-05-11 20:08
Návrat hore  Odpovedať s citátom     

Post your code and your DB scheme. I had a lot of trouble with this earlier on, but fixed with an sqlw.

 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-11 22:10
Návrat hore  Odpovedať s citátom     

modified is a DATE field.

From the setup code:
Kód:
$opts['fdd']['modified'] = array(
  'name'     => 'Modified',
//  'default'  => 'NOW()',
  'select'   => 'T',
  'options'  => 'ACLFPDV',
  'maxlen'   => 19,
  'sort'     => true
//  'sqlw'    => 'NOW()'
);
//$opts['cgi']['overwrite']['modified'] = 'NOW()';



$opts['triggers']['insert']['before'] = 'categories.TIB.inc';
$opts['triggers']['update']['before'] = 'categories.TUB.inc';
// Now important call to phpMyEdiI
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);


The sqlw works, but I don't want to display the field.

The actual trigger (code is same in both the categories.TIB.inc and categories.TUB.inc files:
Kód:
<?php
$newvals['modified'] = 'NOW()';
return true;
?>


I also tried using date, or just inserting a value.

Thanks for the help.

Barry
Kód:



Naposledy upravil k4mg dňa 2007-05-12 14:58, celkom upravené 1 krát

 
aeiche     Založený: 06.04.2007   Príspevky: 10  
Príspevok Zaslal: 2007-05-11 22:17
Návrat hore  Odpovedať s citátom     

Citácia:

The sqlw works, but I don't want to display the field.

I also tried using date, or just inserting a value.

Thanks for the help.

Barry


If that's the only issue, make the field hidden:
'input' => 'H',
'sqlw' => 'now()'

 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-12 11:18
Návrat hore  Odpovedať s citátom     

UPDATE:

I did find one of those stupid mistakes I mention below, using $NOW() vs. NOW(). To my amazement, the triggers still don't work! I added some output to my trigger code, and none of it showed up. I don't think the code is being included at all. I changed the file names, no difference. I tried date() again, no difference. Here is my latest trigger code, I don't know anything more to try. I also changed to the CSV 1.196 version, but that wasn't it.

Kód:
<?php
echo 'Update before change <br >';
//$newvals['modified'] = 'NOW()';
$newvals['modified'] = date("Y-m-d");
print_r($newvals);
return true;
?>


I am using the sqlw option on the actual version of the utility I am using for my computer club's programs database. Using sqlw would be a perfect method, except sqlw doesn't work unless the field is displayed (not hidden). I want to do it with triggers so I don't have to have the field displayed in the update and insert modes. However, thanks for the help, I know there is a way to do this with triggers. They don't seem to be being used at all when I try them. I can place manually a value (like 1999-01-01) in the trigger.inc file, and never see any change at all. I am doing some really simple thing wrong, like mispelling the name of the include file, or the equivelent, and just can't find it. Thanks again for the help.

Barry

 
aeiche     Založený: 06.04.2007   Príspevky: 10  
Príspevok Zaslal: 2007-05-14 17:27
Návrat hore  Odpovedať s citátom     

Citácia:
Using sqlw would be a perfect method, except sqlw doesn't work unless the field is displayed (not hidden).


Hmm... I've been able to make this work several times... here's code for one of my fields:
Kód:

$opts['fdd']['last_verified_date'] = array(
  'name'     => 'Last Time Verified',
  'select'   => 'T',
  'options'    => 'ALVCH',
  'maxlen'   => 11,
  'default'  => '0',
  'sort'     => true,
  'sqlw'    => 'UNIX_TIMESTAMP()',
  'sql|LV'    => 'IF(last_verified_date > 0,FROM_UNIXTIME(last_verified_date),"Never Verified")',
);


The H(idden) flag is up in options (it shouldn't be as the documentation states that it's been moved to 'input' and will not function in 'options' in the future). but that works fine for me. I use timestamps for date recording, but there shouldn't be any difference between that and using an SQL timestamp.

 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-16 13:17
Návrat hore  Odpovedať s citátom     

Thanks for your reply, and of course you are correct. What I want is for the field to display in the View, but not be present in add or update. There is no way to do this, and anyway, I should be able to get the triggers to work, since others are able to.

Barry

 
aeiche     Založený: 06.04.2007   Príspevky: 10  
Príspevok Zaslal: 2007-05-16 17:05
Návrat hore  Odpovedať s citátom     

Citácia:
Thanks for your reply, and of course you are correct. What I want is for the field to display in the View, but not be present in add or update. There is no way to do this, and anyway, I should be able to get the triggers to work, since others are able to.


This is exactly the situation that I have, and mine works fine. What version of PME are you using? (class version).

I've put together a quick and dirty version and tested it, Unless I'm misunderstanding you, this does what you need it to do, here's the code and table def:
Kód:

--- table definition, very basic.
CREATE TABLE `thing` (
  `id` int(11) NOT NULL auto_increment,
  `update_time` int(11) NOT NULL default '0',
  `name` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


INSERT INTO `thing` VALUES (1, 1179331000, 'boog');
INSERT INTO `thing` VALUES (2, 1179331010, 'frank');
       
--------

<h3>table</h3>
<?php

/*
*
* This file was generated by:
*
*                    phpMyEdit version: 5.6
*       phpMyEdit.class.php core class: 1.196
*            phpMyEditSetup.php script: 1.48
*              generating setup script: 1.48
*/

// MySQL host name, user name, password, database, and table
$opts['hn'] = 'localhost';
$opts['un'] = 'username';
$opts['pw'] = 'password';
$opts['db'] = 'database';
$opts['tb'] = 'thing';

$opts['key'] = 'id';

$opts['key_type'] = 'int';

$opts['sort_field'] = array('id');

$opts['inc'] = 15;

$opts['options'] = 'ACPVDF';

$opts['multiple'] = '4';

$opts['navigation'] = 'DB';

$opts['display'] = array(
   'form'  => true,
   'query' => true,
   'sort'  => true,
   'time'  => true,
   'tabs'  => true
);

// Set default prefixes for variables
$opts['js']['prefix']               = 'PME_js_';
$opts['dhtml']['prefix']            = 'PME_dhtml_';
$opts['cgi']['prefix']['operation'] = 'PME_op_';
$opts['cgi']['prefix']['sys']       = 'PME_sys_';
$opts['cgi']['prefix']['data']      = 'PME_data_';

$opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];

$opts['fdd']['id'] = array(
  'name'     => 'ID',
  'select'   => 'T',
  'maxlen'   => 11,
  'sort'     => true
);
$opts['fdd']['update_time'] = array(
  'name'     => 'Update time',
  'select'   => 'T',
  'options'  => 'AVLCD',
  'input'    => 'H',
  'maxlen'   => 11,
  'sort'     => true,
  'sqlw'    => 'UNIX_TIMESTAMP()',
  'sql|LV'    => 'FROM_UNIXTIME(update_time)'
);
$opts['fdd']['name'] = array(
  'name'     => 'Name',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);


// Now important call to phpMyEdit
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);

?>


You should be able to build the table, upload the file and it'll work (assuming you set the username and password and database). The important stuff is all in the 'update_time' field. As before, I use unix timestamps, not mysql datestamps, but again, it's just a matter of functions and field types.

Yes, the triggers should work, but this is a better solution because it's already in the code. Theoretically you should only use triggers to accomplish what you can't with the baseclass.

 
k4mg     Založený: 06.05.2007   Príspevky: 9  
Príspevok Zaslal: 2007-05-17 11:53
Návrat hore  Odpovedať s citátom     

aeiche - Thank you very much for your help and advice. I tried the input hidden suggestion you made, and I now have just what I wanted, the field is displayed, on list and view, but not present on add and change. I really appreciate the help.

Barry

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov