3066 Posts in 866 Topics by 648 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 528 Views |
-
Using ID in Controller

11 January 2011 at 11:14am
Hi
I am looking for help in a small issue I have, so all help would be greatly appreciated.
Within my template I have a control inside another control:
<% control Author %>
$author_name
<% control Top.Book %>
$book_name<br/>
<% end_control %>
<% end_control %>Within my controller I have the following two functions:
public function getAuthor() {
$authorObjects = DataObject::get("author");
return $authorObjects;
}public function getBook() {
$bookObjects = DataObject::get("book", "authorsID={?????}");
return $bookObjects;
}The problem is, I cannot work out how to get the the current author id within the getBook function. See ?????.
Does this make sense. If not, I'll try and explain better.
Many thanks in advance.
Sean
-
Re: Using ID in Controller

12 January 2011 at 9:22am Last edited: 12 January 2011 9:23am
The simplest would be something like this, where you don't need your Page_Controller functions (unless you wish to sort/filter your DataObjects some way):
class Author extends DataObject {
static $has_many = array('Books' => 'Book');
...
}class Book extends DataObject {
static $has_one = array('Author' => 'Author');
...
}<% control Author %>
<p>Name: $Name</p>
<% control Books %>
<p>Book title: $Name</p>
<% end_control %><% end_control %>
Hope this is what you were looking for...
-
Re: Using ID in Controller

12 January 2011 at 11:17am
Hi Martimiz
Problem solved. I now understand my various errors.
Many thanks for taking the time to explain.
Sean
| 528 Views | ||
|
Page:
1
|
Go to Top |
