Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:17:58+00:00 2026-06-05T05:17:58+00:00

I have the following tables: — —————————————————– — Table `product` — —————————————————– CREATE TABLE

  • 0

I have the following tables:

-- -----------------------------------------------------

-- Table `product`

-- -----------------------------------------------------

CREATE  TABLE IF NOT EXISTS `product` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `productName` VARCHAR(255) NULL ,
  `s7location` VARCHAR(255) NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------

-- Table `pages`

-- -----------------------------------------------------

CREATE  TABLE IF NOT EXISTS `pages` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `productID` INT NULL ,
  `pageName` VARCHAR(255) NOT NULL ,
  `isBlank` TINYINT(1) NULL ,
  `pageOrder` INT(11) NULL ,
  `s7page` INT(11) NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `productID` (`productID` ASC) ,
  CONSTRAINT `productID`
    FOREIGN KEY (`productID` )
    REFERENCES `product` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------

-- Table `field`

-- -----------------------------------------------------

CREATE  TABLE IF NOT EXISTS `field` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `pagesID` INT NULL ,
  `fieldName` VARCHAR(255) NOT NULL ,
  `fieldType` VARCHAR(255) NOT NULL ,
  `fieldDefaultValue` VARCHAR(255) NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `id` (`pagesID` ASC) ,
  CONSTRAINT `pagesID`
    FOREIGN KEY (`pagesID` )
    REFERENCES `pages` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

I have gotten CRUD to work on the ‘product’ table.

//addproduct.php
class page_addproduct extends Page {
    function init(){
        parent::init();

        $crud=$this->add('CRUD')->setModel('Product');

    }
}

This works. but I need to get it so that when a new product is created it basically allows me to add new rows into the pages and field tables.

For example, the products in the tables are a print product(like a greeting card) that has multiple pages to render. Page 1 may have 2 text fields that can be customized, page 2 may have 3 text fields, a slider to define text size, and a drop down list to pick a color, and page 3 may have five text fields that can all be customized. All three pages (and all form elements, 12 in this example) are associated with 1 product.

So when I create the product, could i add a button to create a page for that product, then within the page i can add a button to add a new form element field?

I’m still somewhat new to this, so my db structure may not be ideal. i’d appreciate any suggestions and feedback! Could someone point me toward some information, tutorials, documentation, ideas, suggestions, on how I can implement this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:18:00+00:00Added an answer on June 5, 2026 at 5:18 am

    Normally you can’t add page unless you have an existing product. We normally solve that problem with a state field. Add this into your product model:

    $this->addField('state')->enum(array('active','draft'))->defaultValue('draft'); 
    

    also create it in SQL. Also it’s generally good to describe relations, so add this into your product model:

    $this->hasMany('Page','productID');
    

    Next you will need to change the action when a new record is added. You can do that easily by extending crud class:

    class MyCRUD extends CRUD {
        function formSubmitSuccess(){
            if($_GET['id']) return parent::formSubmitSuccess(); // edit ->save
    
            // add ->save handled here
            $this->js()->univ()->location($this->api->url('./details',
              array('id'=>$this->form->model->id)))->execute();
        }
    }
    

    and replacing add(‘CRUD’) with add(‘MyCRUD’). Next if you are placing CRUD on page “mypage” you will need to create “mypage/details”. After successfully saving new product, your new method will redirect user to this new page and it will pass along the productID too.

    On this new page, you should have

    $m=$this->add('Model_Product')->load($_GET['id']); // makes sure ID is valid
    $this->api->stickyGET('id');  // configures page to carry id= value along
    $crud=$this->add('CRUD');
    $crud->setModel($m->ref('Page'));
    

    This will display CRUD here which will automatically edit pages of that particular product. The only thing you miss now is a back button.

    if($crud->grid){
        if($crud->grid->addButton('Save')->isClicked()){
            // AJAX action on button click
    
            $m->set('status','active')->save(); // update status of current product
            $this->js()->univ()->location($this->api->url('..'))->execute();
            // redirect back to parent page
        }
    
        // You might want a cancel button too
        $crud->grid->addButton('Cacel')->js('click')
             ->univ()->location($this->api->url('..'));
    
        // no AJAX, simple javascript action.
    }
    

    To finish everything nicely, go back to your original page and add a condition. You don’t have to create new model, unless you want, can be like this:

    // on my page
    $this->add('MyCRUD')->setModel('Product')->addCondition('state','active');
    

    This way your main CRUD won’t display records which are incomplete. Your database may accumulate draft records which you can delete once in a while. If anything here does not work, publish your project on Github and share it with our Agile Toolkit development group, some of us would certainly implement this for you.

    BONUS:

    You might want how should you edit existing product pages? Easiest would be to have expander in the main crud’s grid:

    $crud=$this->add('MyCRUD');
    $crud->setModel('Product')->addCondition('state','active');
    $crud->addColumn('expander','details'); // will expand into page mypage/details and will automatically pass ID.
    

    This solution is not 100% ideal, but given the character of the WEB applications and their reliance on SQL that’s a great way to manage your data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE IF NOT EXISTS `Person_Categories` ( `PrsCatID` int(11)
I have following tables: CREATE TABLE IF NOT EXISTS stats ( date date NOT
i have following 3 tables CREATE TABLE [dbo].[dspartner]( [dspartnerid] [bigint] IDENTITY(1,1) NOT NULL, [name]
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
I have the following tables Client Table and Product Table ID Name ClientProduct Table
I have the following tables: FACULTY table CREATE TABLE FACULTY ( FACULTY_ID NUMBER(3,0), FACULTY_NAME
I have the following tables: Table A: id int v1 string v2 string Table
I have the following tables: **Product** ProdID int ProdOwner (nvarchar) Views int **Reviews** RevID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.