17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1834 Views |
-
simple table question: help appreciated!

26 December 2007 at 8:59am Last edited: 26 December 2007 9:01am
I'm sure this is a simple question for the PHP/SS experts out there, but I'm stuck. I've worked through the dataobject tutorial, but all I really need is to display a simple table. In this case, it's a list of musical selections, so the headings are 'composer,' 'title,' and 'role.'
I set everything up as specified at the beginning of the tutorial, but I can only get ONE entry (row, whatever you want to call it) to display. I don't know whether this is because of the has_one relation or not.
I created a page (modeled after the "Project" page) called Opera. I changed "Students" (in the tutorial) to Repertoire, and added a few entries. But I can only get a single line of composer/title/role to display:
Composer | Title | Role
Bellini La Donna Alfredo...when I really have several entries I need displayed!
---------------
Here's my code RepProject.php:<?php
/**
* Defines the RepProject page type
*/class RepProject extends Page {
static $has_one = array(
'MyRep' => 'Rep'
);function getCMSFields() {
$fields = parent::getCMSFields();$tablefield = new HasOneComplexTableField(
$this,
'MyRep',
'Rep',
array(
'Composer' => 'Composer',
'Title' => 'Title',
'Role' => 'Role'
),
'getCMSFields_forPopup'
);$fields->addFieldToTab( 'Root.Content.Rep', $tablefield );
return $fields;
}
}class Project_Controller extends Page_Controller {
}
?>-----------------------------
and the SS template:
<div id="Content" class="typography"><h2>$Title</h2>
$Content
<h3>Repertoire</h3>
<table id="Rep">
<thead>
<tr>
<th>Composer</th>
<th>Title</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<% control MyRep %>
<tr>
<td><p><strong>$Composer</strong></p></td>
<td><p><strong>$Title</strong></p></td>
<td><p><strong>$Role</strong></p></td>
</tr>
<% end_control %>
</tbody></table>$Form
$PageComments</div>
-----------------------Sorry to sound like a Php/MySQL retard, but I've struggled with this for hours - and now I'm finally appealing for help. My relationships are much simpler than what's in the tutorial... I just need to know how to spit out the whole table! Thank you so much, any help is appreciated.
-
Re: simple table question: help appreciated!

26 December 2007 at 9:31am
When you want to have more than one 'Rep' on a RepProject you'll have to use a has_many relationship, otherwise it will have the id in the same table and you will not be able to save more than one Rep on a RepProject.
A has_many relationship creates a different 'lookup' table that connects the both tables through ID's.
You might have to use a HasManyComplexTableField in that case too.
(At least that's what I think).
-
Re: simple table question: help appreciated!

26 December 2007 at 1:26pm
Thanks for the reply...I also suspected I might need has_many, but simply changing the type of array hasn't helped. When I change the following items (in bold), I get an error and can't even edit any of the repertoire pages in the admin:
Repproject.php
<?php
/**
* Defines the Project page type
*/class Project extends Page {
static $has_many = array(
'MyRep' => 'Rep'
);function getCMSFields() {
$fields = parent::getCMSFields();$tablefield = new HasManyComplexTableField(
$this,
'MyRep',
'Rep',
array(
'Composer' => 'Composer',
'Title' => 'Title',
'Role' => 'Role'
),
'getCMSFields_forPopup'
);$fields->addFieldToTab( 'Root.Content.Rep', $tablefield );
return $fields;
}
}class Project_Controller extends Page_Controller {
}
?>---------------
What I need is something similar to what's on this site: http://carladirlikov.com/main.asp, then click "Repertoire." Some composers could have more than one work associated with them, or one work might have 1+ roles, but for the most part, it's just one composer, work, and role per line.
Honestly, I've taken a look at the sections in the Wiki about tablelistfields and dataobjects, but I was still confused. Most of the tutorials are about very complex relationships, and I don't need to know how to sort, etc.
If anyone has a way to explain has_many in simple, newbie terms, I'd be forever indebted. I'm willing to invest the time to learn more about SS because it's turning out to be exactly what I need for several projects. This one aspect of the coding is just slowing me down - and it's definitely operator error! ;)
thank you in advance.
-
Re: simple table question: help appreciated!

26 December 2007 at 9:12pm
Take a look at
HasMany is described there.
You'll need a has_one relationship on the other side too. -
Re: simple table question: help appreciated!

27 December 2007 at 3:14am
I spent all afternoon on the Dataobject Relation tutorial yesterday. But I'm not in need of different pages using the same tables, just one page with one associated table.
Dio - what do you mean when you say "the other side"?
-
Re: simple table question: help appreciated!

27 December 2007 at 3:24am
Well, you do need one page that has many 'repertoires', don't you?
So you need one repertoireholder and a repertoire object.The holder is your 'RepProject'.
Then you also need a 'repertoire' object (that extends DataObject). That object is the 'other side'.
Please go through that part of the tutorial that I told you. It's really that what you need.
It's quite easy:
- a repertoireholder page with has_many repertoire objects.
- one repertoire object with has_one repertoire holder.I must admit I haven't actually used a hasmanycomplextablefield myself, but I will in the coming weeks. However I've used has_many relationships a few times...
-
Re: simple table question: help appreciated!

27 December 2007 at 5:14am
Ok, thanks for spelling that out. I'm going to start from scratch and work my way through the entire tutorial. Maybe some lightbulbs will go off - I know it's a matter of something very basic I'm overlooking.
| 1834 Views | ||
|
Page:
1
|
Go to Top |


