And when I thought everything is fine ... I am confused:
StudentPage.php and FacultyPage.php are almost identical with the difference that they declare
< class StudentPage extends Page {
> class FacultyPage extends Page {
< class StudentPage_Controller extends Page_Controller {
---
> class FacultyPage_Controller extends Page_Controller {
Then StudentHolder.php
class StudentHolder extends Page {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('StudentPage');
}
class StudentHolder_Controller extends Page_Controller {
function StudentSearchForm()
{
return new Form(
$this,
"StudentSearchForm",
new FieldSet(new TextField('FirstName','First Name starts from'), new TextField('LastName','Last Name starts from')),
new FieldSet(new FormAction('doStudentSearch','Search'))
);
}
function doStudentSearch($data, $form)
{
$results = DataObject::get("SiteTree","ClassName IN('StudentPage') AND lastname LIKE '".$data['LastName']."%' AND firstname LIKE '".$data['FirstName']."%'");
return $this->customise(array('StudentSearchResults' => $results))->renderWith(array('StudentSearch_results','Page'));
}
}
?>
and FacultyHolder.php is a copy with Student replaced by Faculty everywhere.
Then
StudentSearch_results.ss
<div class="typography">
$StudentSearchForm
<% if StudentSearchResults %>
<ul>
<% control StudentSearchResults %>
<li><a href="$Link">$firstname $lastname</a></li>
<% end_control %>
</ul>
<% else %>
There were no results that matched your query.
<% end_if %>
</div>
and FacultySearch_results.ss is again just replacement Student to Faculty
Here is a strange part:
if I put either StudentPage.php, StudentHolder.php or FacultyPage.php, FacultyHolder.php into code and flush db, the corresponding search works perfectly.
if I put StudentPage.php, StudentHolder.php and FacultyPage.php, FacultyHolder.php into code and flush db both searches end up with SilverStripe error
The tables in db should be completely independent but the fields have the same names. May be this is the source of error?
However we have a lot of resons to have the same field names in both tables
Any suggestions? Thanks you in advance. Victor