i need some insight on how i should handle this app im working on. right now im using…
- User
i need some insight on how i should handle this app im working on. right now im using yii2 mvc, i have contact messages database that works with the contact form, so i receive msg into it and email. works fine. i also have inquiries that is its own mvc, kinda similar but has a different purpose. now im realizing i need another database for order messages, for when theirs issues. but going to three different pages to handle all these messages is pain, and was wondering if you have any thoughts on how to approach this.
- Assistant
- User
interesting. but only i issue i have with this, is that the views are different. since for example the contact message is setup that when i reply within the view update page, it sends a email directed towards the contact that messaged me. i was thinking using this also for the inquiry. since its main purpose is sending a reply via email back to whom is inquiring. the order messaging is more focused within the app, sending a message within the order page, and via email.
- Assistant
- User
so your still suggesting a centralized message management system?
- Assistant
- User
so how would you code it for a yii2 app
- Assistant
- User
my contact message migration:
$this->createTable('{{%contact}}', [ 'id' => $this->primaryKey(), 'name' => $this->string(), 'email' => $this->string()->notNull(), 'subject' => $this->text()->notNull(), 'body' => $this->text()->notNull(), // Unread = 0, Read = 1, Important = 2, Spam = 10 'status' => $this->smallInteger()->notNull()->defaultValue(0), // New Message = 1, else 0 'new_message' => $this->tinyInteger()->notNull()->defaultValue(1), /** * Inserted 'replied * @see app/migrations/m241030_200601_insert_replied_contact_table.php * 'replied' => $this->text(),//*/ /** * IpBehavior uses 'created_ip', 'updated_ip' * @see app/components/behaviors/IpBehavior.php */ 'created_ip' => $this->string(45),// Store IP address (supports IPv4/IPv6). 'updated_ip' => $this->string(45), /** * BlameableBehavior * @url https://www.yiiframework.com/doc/api/2.0/yii-behaviors-blameablebehavior */ 'created_by' => $this->integer(),//->notNull(), Note: Guest and user created. 'updated_by' => $this->integer(), /** * Timestamp/dateTime and Behavior * @url https://www.yiiframework.com/doc/api/2.0/yii-behaviors-timestampbehavior * @see models/User.php * * Use the below code with $this->datetime() * * TimestampBehavior::className(), 'value' => new Expression('NOW()') * 'created_at' => $this->datetime()->notNull(), 'updated_at' => $this->datetime(),//*/ 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer(), ], $tableOptions); // BlameableBehavior: index `created_by` and `updated_by` in `{{%contact}}` with foreign keys to `{{%user}}.id`, cascade delete. $this->createIndex('{{%idx-contact-created_by}}', '{{%contact}}', 'created_by'); $this->addForeignKey('{{%fk-contact-created_by}}', '{{%contact}}', 'created_by', '{{%user}}', 'id', 'CASCADE'); $this->createIndex('{{%idx-contact-updated_by}}', '{{%contact}}', 'updated_by'); $this->addForeignKey('{{%fk-contact-updated_by}}', '{{%contact}}', 'updated_by', '{{%user}}', 'id', 'CASCADE'); - Assistant
- User
any suggestions on the controller for the index using gridview and making it noticeable which is what.
- Assistant
- User
about about using search file with the mvc? instead of using activeDataProvider here and use it within the search.
- Assistant
- User
i never seen this before: 'status' => "ENUM('new', 'in progress', 'resolved') NOT NULL DEFAULT 'new'",
is it like using a const?
- Assistant
- User
i take it written like so "'status' => "ENUM('new', 'in progress', 'resolved') NOT NULL DEFAULT 'new'"," because yii mirgration does not have a way to handle it
- Assistant
- User
this is how yii2 recommands the handling of said feature, using const. handling how they operate within the rules function.
- Assistant
- User
so the 'type' => "ENUM('contact', 'inquiry', 'order') NOT NULL", you suggest is more in less the same thing.. handled as a const.. etc bla bla bla
- Assistant
- User
with this in mind, could you rewrite the code for the messaging management system. keeping in mind the migration needs to be this:
public function Up() { $this->createTable('{{%messages}}', [ 'id' => $this->primaryKey(), 'type' => "ENUM('contact', 'inquiry', 'order') NOT NULL",// change this to tiny int. 'name' => $this->string(), 'email' => $this->string()->notNull(), 'subject' => $this->text()->notNull(),// not sure if using ->notNull() is ideal, since contact form needs it, inquiry i could preset, order guess i could use the orderId. 'body' => $this->text()->notNull(), 'status' => $this->smallInteger()->notNull()->defaultValue(0),// Unread = 0, Read = 1, Important = 2, Spam = 10 'new_message' => $this->tinyInteger()->notNull()->defaultValue(1),// New Message = 1, else 0 'replied' => $this->text(), 'created_ip' => $this->string(45),// Store IP address (supports IPv4/IPv6). 'updated_ip' => $this->string(45), 'created_by' => $this->integer(),//->notNull(), Note: Guest and user created. 'updated_by' => $this->integer(), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer(), ]); $this->createIndex('{{%idx-contact-created_by}}', '{{%contact}}', 'created_by'); $this->addForeignKey('{{%fk-contact-created_by}}', '{{%contact}}', 'created_by', '{{%user}}', 'id', 'CASCADE'); $this->createIndex('{{%idx-contact-updated_by}}', '{{%contact}}', 'updated_by'); $this->addForeignKey('{{%fk-contact-updated_by}}', '{{%contact}}', 'updated_by', '{{%user}}', 'id', 'CASCADE'); // Optionally, you can create indexes or foreign keys as needed. } public function Down() { $this->dropTable('{{%messages}}'); } - Assistant
- User
- Assistant