Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>I created a three tables in the database - trip, landmark and landmarktrip with the following definitions.</p> <pre><code>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'); </code></pre> <p>And then created models in wwwroot/website/lib/Model as follows</p> <p><strong>Landmark.php</strong></p> <pre><code>class Model_Landmark extends Model_Table { public $entity_code='landmark'; public $table_alias='l'; function init(){ parent::init(); $this-&gt;addField('id')-&gt;mandatory(true)-&gt;system(true)-&gt;visible(false); $this-&gt;addField('name')-&gt;mandatory(true); } } </code></pre> <p><strong>Trip.php</strong></p> <pre><code>class Model_Trip extends Model_Table { public $entity_code='trip'; public $table_alias='t'; function init(){ parent::init(); $this-&gt;addField('id')-&gt;mandatory(true)-&gt;system(true)-&gt;visible(false); $this-&gt;addField('user_id')-&gt;defaultValue($this-&gt;api-&gt;auth-&gt;get('id'))-&gt;visible(false); $this-&gt;addField('name')-&gt;mandatory(true); $this-&gt;addField('short_desc')-&gt;mandatory(true); $this-&gt;addField('start_date')-&gt;dataType('date')-&gt;mandatory(true); } } } </code></pre> <p><strong>LandmarkTrip.php</strong></p> <pre><code>class Model_LandmarkTrip extends Model_Table { public $entity_code='landmarktrip'; public $table_alias='lt'; function init(){ parent::init(); $this-&gt;addField('id')-&gt;system(true)-&gt;visible(false); $this-&gt;addField('trip_id')-&gt;refModel('Model_Trip')-&gt;mandatory(true); $this-&gt;addField('landmark_id')-&gt;refModel('Model_Landmark')-&gt;mandatory(true); } } </code></pre> <p>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.</p> <p><strong>trips.php</strong></p> <pre><code>class page_trips extends page { function init() { parent::init(); $p=$this; $c=$p-&gt;add('CRUD')-&gt;setModel('Trip'); $c-&gt;setMasterField('user_id', $this-&gt;api-&gt;auth-&gt;get('id')); } } </code></pre> <p><strong>itinerary.php</strong></p> <pre><code>class page_itinerary extends page { function init() { parent::init(); $p=$this; $this-&gt;js()-&gt;_load('trip_univ'); $triplist=$this-&gt;api-&gt;db-&gt;dsql()-&gt;table('trip t') -&gt;field('t.id') -&gt;field('t.name') -&gt;where('t.user_id', $p-&gt;api-&gt;auth-&gt;get('id')) -&gt;order('t.start_date') -&gt;do_getAssoc(); if ($_GET['trip']){ $curr_trip=$_GET['trip']; } else { $earliest=$this-&gt;api-&gt;db-&gt;dsql()-&gt;table('trip') -&gt;field('min(start_date)') -&gt;where('user_id',$this-&gt;api-&gt;auth-&gt;get('id')) -&gt;do_getOne(); $curr_trip=$this-&gt;api-&gt;db-&gt;dsql()-&gt;table('trip') -&gt;field('id') -&gt;where('user_id',$this-&gt;api-&gt;auth-&gt;get('id')) -&gt;where('start_date',$earliest) -&gt;do_getOne(); } $f=$p-&gt;add('Form')-&gt;setFormClass('horizontal'); $list=$f-&gt;addField('dropdown','trip')-&gt;setValueList($triplist)-&gt;set($curr_trip); $list-&gt;js('change')-&gt;univ()-&gt;viewTrip($p-&gt;api-&gt;getDestinationURL(null), $list); $lt=$p-&gt;add('CRUD')-&gt;setModel('LandmarkTrip'); $lt-&gt;setMasterField('trip_id', $curr_trip); } } </code></pre> <p>and one last file which allows the list to change the grid Create a file called trips_univ.js in wwwroot/website/templates/js</p> <p><strong>trip_univ.js</strong></p> <pre><code>$.each({ viewTrip: function(url, name){ document.location.href=url+'&amp;trip='+$(name).val(); } },$.univ._import); </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload