如何在 Atk4 中引用一个表单的填写与另一个表单的填写

发布于 2024-12-09 14:13:12 字数 828 浏览 0 评论 0原文

我为登录用户制作了两种表格。第一个用于旅行信息(名称、简短描述),第二个用于当前用户旅行的不同地标(名称、描述)。是否可以将用户与填写旅行表格和将多次用于不同地标的地标表格“联系起来”。我有模型“trips”、“user”和“landmarks”以及各自的id,但我无法单独解决问题。

........................

我已经尝试过这个并且它发生了(感谢Romaninsh):

function page_trips(){
$this->api->stickyGET('id');
$id=$this->api->auth->get('id');
$f=$this->add('Form');
$f->addField('line','name')->setNotNULL();
$f->addField('Text','short_desc')->setNotNULL();
$f->setSource('trips');
$f->setConditionFromGET();
$f->dq
     ->set('user_id',$id);
$f->addSubmit('Next');
if($f->isSubmitted())
{
    $f->update();

    $f->js()->univ()->location($this->api->getDestinationUrl('../targets')
    )

    ->execute();
}
}

现在我可以输入有关新旅行的信息并保存到表格与各自的用户 ID。剩下的任务是向当前行程添加不同的地标。

I have made two forms for logged users. The first one is for trip info (name, short description) and the second is for different landmarks (name, description) that are part of the trip of current user. Is it possible to "connect" the user with filling of trip form and the form for landmarks that is going to be used several times for different landmarks. I have the models "trips", "user" and "landmarks" with respective id's, but I can not solve the problem alone.

........................

I have tried this and it happened (thanks to Romaninsh):

function page_trips(){
$this->api->stickyGET('id');
$id=$this->api->auth->get('id');
$f=$this->add('Form');
$f->addField('line','name')->setNotNULL();
$f->addField('Text','short_desc')->setNotNULL();
$f->setSource('trips');
$f->setConditionFromGET();
$f->dq
     ->set('user_id',$id);
$f->addSubmit('Next');
if($f->isSubmitted())
{
    $f->update();

    $f->js()->univ()->location($this->api->getDestinationUrl('../targets')
    )

    ->execute();
}
}

Now I can enter an info about new trip and save to table with respective user id. The rest of the task is to add different landmarks to current trip.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟月 2024-12-16 14:13:12

不确定这是否是您正在寻找的,因为我使用了两页设计,您可能会使用另一页设计来添加/编辑/删除地标,但这也许会给您一些想法。

我在数据库中创建了三个表——trip、landmark和landmarktrip,其定义如下。

CREATE TABLE IF NOT EXISTS `landmark` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET latin1 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=6 ;

INSERT INTO `landmark` (`id`, `name`) VALUES
(1, 'Xintiandi'),
(2, 'Pearl TV Tower'),
(3, 'YuYuan Gardens'),
(4, 'Shanghai Botanical Gardens'),
(5, 'Shanghai World Financial Centre');

CREATE TABLE IF NOT EXISTS `landmarktrip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trip_id` int(10) NOT NULL,
  `landmark_id` int(10) NOT NULL,
  PRIMARY KEY (`id`) 
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=7 ;

INSERT INTO `landmarktrip` (`id`, `trip_id`, `landmark_id`) VALUES
(1, 1, 1),
(2, 1, 2),
(3, 1, 3),
(4, 2, 3),
(5, 2, 4),
(6, 1, 5);

CREATE TABLE IF NOT EXISTS `trip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `name` varchar(255) COLLATE utf8_bin NOT NULL,
  `short_desc` varchar(255) COLLATE utf8_bin NOT NULL,
  `start_date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='7741244' AUTO_INCREMENT=3 ;

INSERT INTO `trip` (`id`, `user_id`, `name`, `short_desc`, `start_date`) VALUES
(1, 1, 'Shanghai 1', 'First Trip To China', '2011-10-13'),
(2, 1, 'Shanghai 2', 'Return Visit', '2011-10-21');

然后在wwwroot/website/lib/Model中创建模型如下

Landmark.php

class Model_Landmark extends Model_Table {
   public $entity_code='landmark';
   public $table_alias='l';

   function init(){ 
     parent::init();
     $this->addField('id')->mandatory(true)->system(true)->visible(false);
     $this->addField('name')->mandatory(true);
   }
}

Trip.php

class Model_Trip extends Model_Table {
    public $entity_code='trip';
    public $table_alias='t';

    function init(){
        parent::init();
        $this->addField('id')->mandatory(true)->system(true)->visible(false);


 $this->addField('user_id')->defaultValue($this->api->auth->get('id'))->visible(false);
        $this->addField('name')->mandatory(true);
        $this->addField('short_desc')->mandatory(true);
        $this->addField('start_date')->dataType('date')->mandatory(true);
    }
  } 
} 

LandmarkTrip.php

class Model_LandmarkTrip extends Model_Table {
    public $entity_code='landmarktrip';
    public $table_alias='lt';

  function init(){
       parent::init();
       $this->addField('id')->system(true)->visible(false);  
           $this->addField('trip_id')->refModel('Model_Trip')->mandatory(true);
       $this->addField('landmark_id')->refModel('Model_Landmark')->mandatory(true);
  }
}

在wwwroot/中创建两个页面网站/页面,一个用于添加行程,一个用于添加行程,因为我不知道您使用的表单方法如何,您可以选择您想要查看详细信息的行程。

trips.php

class page_trips extends page {
 function init() {
   parent::init();
   $p=$this;

   $c=$p->add('CRUD')->setModel('Trip');
   $c->setMasterField('user_id', $this->api->auth->get('id'));

  }
}

itinerary.php

class page_itinerary extends page {

  function init() {
    parent::init();
    $p=$this;

    $this->js()->_load('trip_univ');

    $triplist=$this->api->db->dsql()->table('trip t')
              ->field('t.id')
              ->field('t.name')
              ->where('t.user_id', $p->api->auth->get('id'))
              ->order('t.start_date')
              ->do_getAssoc();


    if ($_GET['trip']){
          $curr_trip=$_GET['trip'];
    } else {
          $earliest=$this->api->db->dsql()->table('trip')
                   ->field('min(start_date)')
                   ->where('user_id',$this->api->auth->get('id'))
                   ->do_getOne();

          $curr_trip=$this->api->db->dsql()->table('trip')
                   ->field('id')
                   ->where('user_id',$this->api->auth->get('id'))
                   ->where('start_date',$earliest)
                   ->do_getOne();
    }

    $f=$p->add('Form')->setFormClass('horizontal');
    $list=$f->addField('dropdown','trip')->setValueList($triplist)->set($curr_trip);
    $list->js('change')->univ()->viewTrip($p->api->getDestinationURL(null), $list);


    $lt=$p->add('CRUD')->setModel('LandmarkTrip');
    $lt->setMasterField('trip_id', $curr_trip);

  }
}

以及最后一个允许列表更改网格的文件
在 wwwroot/website/templates/js 中创建一个名为 trips_univ.js 的文件

trip_univ.js

$.each({
    viewTrip: function(url, name){
              document.location.href=url+'&trip='+$(name).val();
    }
},$.univ._import);

现在,您可以使用 CRUD 来添加、编辑和删除行来创建行程。
然后进入行程页面,从下拉列表中选择行程,或者默认为最早的行程,并且可以添加、删除或编辑行程中的地标。

Not sure if it's what you are looking as i used a two page design and you would probably use another one to add/edit/delete landmarks but maybe this will give you some ideas.

I created a three tables in the database - trip, landmark and landmarktrip with the following definitions.

CREATE TABLE IF NOT EXISTS `landmark` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET latin1 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=6 ;

INSERT INTO `landmark` (`id`, `name`) VALUES
(1, 'Xintiandi'),
(2, 'Pearl TV Tower'),
(3, 'YuYuan Gardens'),
(4, 'Shanghai Botanical Gardens'),
(5, 'Shanghai World Financial Centre');

CREATE TABLE IF NOT EXISTS `landmarktrip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trip_id` int(10) NOT NULL,
  `landmark_id` int(10) NOT NULL,
  PRIMARY KEY (`id`) 
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=7 ;

INSERT INTO `landmarktrip` (`id`, `trip_id`, `landmark_id`) VALUES
(1, 1, 1),
(2, 1, 2),
(3, 1, 3),
(4, 2, 3),
(5, 2, 4),
(6, 1, 5);

CREATE TABLE IF NOT EXISTS `trip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `name` varchar(255) COLLATE utf8_bin NOT NULL,
  `short_desc` varchar(255) COLLATE utf8_bin NOT NULL,
  `start_date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='7741244' AUTO_INCREMENT=3 ;

INSERT INTO `trip` (`id`, `user_id`, `name`, `short_desc`, `start_date`) VALUES
(1, 1, 'Shanghai 1', 'First Trip To China', '2011-10-13'),
(2, 1, 'Shanghai 2', 'Return Visit', '2011-10-21');

And then created models in wwwroot/website/lib/Model as follows

Landmark.php

class Model_Landmark extends Model_Table {
   public $entity_code='landmark';
   public $table_alias='l';

   function init(){ 
     parent::init();
     $this->addField('id')->mandatory(true)->system(true)->visible(false);
     $this->addField('name')->mandatory(true);
   }
}

Trip.php

class Model_Trip extends Model_Table {
    public $entity_code='trip';
    public $table_alias='t';

    function init(){
        parent::init();
        $this->addField('id')->mandatory(true)->system(true)->visible(false);


 $this->addField('user_id')->defaultValue($this->api->auth->get('id'))->visible(false);
        $this->addField('name')->mandatory(true);
        $this->addField('short_desc')->mandatory(true);
        $this->addField('start_date')->dataType('date')->mandatory(true);
    }
  } 
} 

LandmarkTrip.php

class Model_LandmarkTrip extends Model_Table {
    public $entity_code='landmarktrip';
    public $table_alias='lt';

  function init(){
       parent::init();
       $this->addField('id')->system(true)->visible(false);  
           $this->addField('trip_id')->refModel('Model_Trip')->mandatory(true);
       $this->addField('landmark_id')->refModel('Model_Landmark')->mandatory(true);
  }
}

Created two pages in wwwroot/website/page, one to add the trips and one for the itinerary as i dont see how with the form approach you are using, you can select which trip you want to see the details of.

trips.php

class page_trips extends page {
 function init() {
   parent::init();
   $p=$this;

   $c=$p->add('CRUD')->setModel('Trip');
   $c->setMasterField('user_id', $this->api->auth->get('id'));

  }
}

itinerary.php

class page_itinerary extends page {

  function init() {
    parent::init();
    $p=$this;

    $this->js()->_load('trip_univ');

    $triplist=$this->api->db->dsql()->table('trip t')
              ->field('t.id')
              ->field('t.name')
              ->where('t.user_id', $p->api->auth->get('id'))
              ->order('t.start_date')
              ->do_getAssoc();


    if ($_GET['trip']){
          $curr_trip=$_GET['trip'];
    } else {
          $earliest=$this->api->db->dsql()->table('trip')
                   ->field('min(start_date)')
                   ->where('user_id',$this->api->auth->get('id'))
                   ->do_getOne();

          $curr_trip=$this->api->db->dsql()->table('trip')
                   ->field('id')
                   ->where('user_id',$this->api->auth->get('id'))
                   ->where('start_date',$earliest)
                   ->do_getOne();
    }

    $f=$p->add('Form')->setFormClass('horizontal');
    $list=$f->addField('dropdown','trip')->setValueList($triplist)->set($curr_trip);
    $list->js('change')->univ()->viewTrip($p->api->getDestinationURL(null), $list);


    $lt=$p->add('CRUD')->setModel('LandmarkTrip');
    $lt->setMasterField('trip_id', $curr_trip);

  }
}

and one last file which allows the list to change the grid
Create a file called trips_univ.js in wwwroot/website/templates/js

trip_univ.js

$.each({
    viewTrip: function(url, name){
              document.location.href=url+'&trip='+$(name).val();
    }
},$.univ._import);

So now, you can create trips using the CRUD to add, edit and delete rows.
Then go to the itinerary page to select a trip from the dropdown list or it defaults to the earliest trip and can add, remove or edit landmarks from the trip.

萌︼了一个春 2024-12-16 14:13:12

由于您已经部分解决了问题,我只需要添加一些有关如何将多个操作合并到表单中的注释。

$form->setModel('Trip');
$form->addField('line','extrainfo'):

if($form->isSubmitted()){
    $form->update();

    $it=$this->add('Model_Itinerary');
    $it->set('trip_id', $form->getModel()->get('id'));
    $it->set('extrainfo', $form->get('extrainfo'));
    $it->update();
}

这样,您可以在保存表单时创建多个模型。

As you have solved your problem partially, I just need to add some notes on how to incorporate multiple actions into the form.

$form->setModel('Trip');
$form->addField('line','extrainfo'):

if($form->isSubmitted()){
    $form->update();

    $it=$this->add('Model_Itinerary');
    $it->set('trip_id', $form->getModel()->get('id'));
    $it->set('extrainfo', $form->get('extrainfo'));
    $it->update();
}

This way you can create multiple models when the form is saved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文