In my Typo3 extension ,I want one of my table column as 'datetime' with type as'timestamp' and default as 'CURRENT_TIMESTAMP'.
How can I create this in TCA file.
I have given my code below. But this is not creating the column with type timespamp and default value as CURRENT_TIMESTAMP.
'datetime' => array(
'exclude' => 0,
'label' => 'LLL:EXT:besi_jobs/locallang_db.xml:tx_jobs_messages.datetime',
'config' => array(
'type' => 'timestamp',
'size' => '12',
'max' => '20',
'eval' => 'datetime',
'checkbox' => '0',
'default' => 'CURRENT_TIMESTAMP'
)
),
The type must be set to 'input':
'datetime' => array(
'exclude' => 0,
'label' => 'LLL:EXT:besi_jobs/locallang_db.xml:tx_jobs_messages.datetime',
'config' => array(
'type' => 'input',
'size' => '12',
'max' => '20',
'eval' => 'datetime',
'checkbox' => '0',
'default' => time(),
)
),
NOTES
All the possible types are described in the TCA reference.
The field in the .sql file file of your extension should be int(11) unsigned NOT NULL DEFAULT '0'. The TCA definition neither creates nor alters the database. It only defines how the field is displayed in the forms.
Related
I am doing a migration file, and there is a field on a table wich type should be DateTime, and the default value CURRENT_TIMESTAMP. What I have until now is the next:
'date' => array(
'type' => 'DATETIME',
),
I think it is right... but I still need set the default value... definitely, what I want to do is make the translation from sql to codeigniter migration of this:
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
Thanks in advance.
Best way to Codeigniter migration:
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'first_name' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null'=>false,
),
'last_name' => array(
'type' => 'VARCHAR',
'constraint' => 50,
'null'=>false,
),
'email' => array(
'type' => 'VARCHAR',
'constraint' => 100,
'unique' => true,
'null'=>false,
),
'mobile' => array(
'type' => 'BIGINT',
'constraint' => 15,
'null'=>true,
),
'password' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null'=>false,
),
'image' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null'=>true,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 3,
'default'=>1,
),
'delete_status' => array(
'type' => 'TINYINT',
'constraint' => 3,
'default'=>1,
),
'created_date datetime default current_timestamp',
'updated_date datetime default current_timestamp on update current_timestamp',
));
You can try like this.Need to use timestamp.See an example below..
'created_at' => array('type' => 'timestamp')
I have found this answer in the codeigniter forum. Basically, it says that I can use created_at timestamp default current_timestampinstead of key->value array. And there are other interesant things like 'on update':
'updated_at' => array(
'type' => 'varchar',
'constraint' => 250,
'null' => true,
'on update' => 'NOW()'
)
I hope it can to help anyone on future.
I want to set on update attributes for getting an updated time for my application. Here is my Model Code:
public function createDatabase() {
$testdatabase = "testdatabase";
$this->dbforge->create_database($testdatabase);
$this->db->db_select($testdatabase);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 1,
'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'establishment_date' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE,
),
'package' => array(
'type' => 'VARCHAR',
'constraint' => '15',
),
'db_name' => array(
'type' => 'VARCHAR',
'constraint' => '25',
),
'update_date' => array(
'type' => 'datetime',
'on update' => 'NOW()',
),
'upgrade' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '0',
),
'status' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '4',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_field("subscription_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
$this->dbforge->add_field("subscription_expire TIMESTAMP DEFAULT '0000-00-00 00:00:00'");
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('tms_profile');
}
Table is successfully created but on update attributes not exists on the field named update_date. i want to set on update atrributes on the field.
All you have to do is change type of update_date column like
....
'update_date' => array(
'type' => 'TIMESTAMP'
),
.....
Now it will work ON UPDATE with NOW()
use inline declaration, like here:
`update_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
I'm learning CodeIgniter and now I wan to create MySQL table with DATETIME field.
I have this code in Install_Model.php
$Fields = array(
'ID' => array(
'Type' => 'INT',
'Constraint' => 10,
'Unsigned' => TRUE,
'Auto_Increment' => TRUE
),
'Username' => array(
'Type' => 'VARCHAR',
'Constraint' => '255'
),
'Password' => array(
'Type' => 'VARCHAR',
'Constraint' => '255'
),
'AddDate' => array(
'Type' => 'DATETIME'
)
);
$this->dbforge->add_key('ID', TRUE);
$this->dbforge->add_field($Fields);
$this->dbforge->create_table('Admins', TRUE);
echo 'Table Admins created successfully!<br/>';
When I execute this code I get this error:
Warning: #1265 Data truncated for column 'AddDate' at row 1
And in filed AddDate content is 0000-00-00 00:00:00
How I can fix problem, and make AddDate content current timestamp?
I tried to set DEFAULT CURRENT_TIMESTAMP but then CodeIgniter returns error in SQL query :(
Try
'AddDate' => array(
'type' => 'datetime',
'default' => '0000-00-00 00:00:00',
)
'AddDate' => array(
'type' => 'TIMESTAMP',
)
Add these in your model, it will automatically add current datetime on creation, updation adn deletion etc.
protected $createdField = 'AddDate';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
I use a frontend plugin to insert data into the database. Via Typo3 (TCA) the record can be viewed in Backend.
The problem:
If there are breaks in the textarea from the frontend form its displayed inside the record like this:
test\r\ntest\r\ntest
What i already tried are different kind of escaping, nl2br, explodes, and so on.
How does the database-field should look like, so the breaks are displayed well?
Here is some code:
'note' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_eventform/locallang_db.xml:tx_XYZ_data.note',
'config' => array(
'type' => 'text',
'cols' => '30',
'rows' => '5',
)
),
$field_values = array(
'note' => mysql_real_escape_string($_REQUEST['note']),
);
You need to use TCA type 'none' for backend. But this field is not editable.
'note' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_eventform/locallang_db.xml:tx_XYZ_data.note',
'config' => array(
'type' => 'none',
'cols' => '30',
'rows' => '5',
'pass_content' => true,
)
),
And you need to use nl2br() function while storing value to database.
$field_values = array(
'note' => nl2br($_REQUEST['note']),
);
Im using Drupal version 6.19 and the webform module in Drupal to create forms.I have two forms on my site.When the user submits the form, where in the drupal database are the entries saved for each form ?
Please help
Thank You
Just take a look at its database schema in webform.install.
...
$schema['webform_submitted_data'] = array(
'description' => 'Stores all submitted field data for webform submissions.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sid' => array(
'description' => 'The unique identifier for this submission.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => 'The identifier for this component within this node, starts at 0 for each node.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'no' => array(
'description' => 'Usually this value is 0, but if a field has multiple values (such as a time or date), it may require multiple rows in the database.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '0',
),
'data' => array(
'description' => 'The submitted value of this field, may be serialized for some components.',
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
),
'indexes' => array(
'nid' => array('nid'),
'sid_nid' => array('sid', 'nid'),
),
'primary key' => array('nid', 'sid', 'cid', 'no'),
);
...
You should use:
First, log in to mysql
After, use database_name;
You must replace with the name of the database
Then, show tables;
The last sentence will show you the tables of tha database
Now, select * from webform_submitted_data;
You should be able to see the data.
You can also view submitted data by navigating to Content Management > Webforms. I believe the data is serialized in the database, so if you have large forms its not an easy read.