3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 926 Views |
-
custom controller doesn't work, why?

24 March 2009 at 6:14am Last edited: 24 March 2009 6:15am
Hi,
I have a PersonsHolder with several PersonsPage-children. With a dropdown ('Show' => "Enum('Featured,Standard,Do not show','Standard')") in PersonsPage it is decided how the childpage is shown in the PersonsHolder.
To accomplish this, I would like to create a custom controller. Based on the second tutorial and this post I wrote:
class PersonsHolder_Controller extends Page_Controller{
...
function Accent() {
return DataObject::get("PersonsPage","Show = Standard");
}
}
In PersonsHolder.ss I call this control like this:<% control Accent %>
<a href="$URLSegment">$Title</a>
<% end_control %>However... I get the following error:
[User Error] Couldn't run query: SELECT `SiteTree_Live`.*, `Page_Live`.*, `PersonsPage_Live`.*, `SiteTree_Live`.ID, if(`SiteTree_Live`.ClassName,`SiteTree_Live`.ClassName,'SiteTree') AS RecordClassName FROM `SiteTree_Live` LEFT JOIN `Page_Live` ON `Page_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `PersonsPage_Live` ON `PersonsPage_Live`.ID = `SiteTree_Live`.ID WHERE (Show = Standard) AND (`SiteTree_Live`.ClassName IN ('PersonsPage')) AND (`SiteTree_Live`.SubsiteID IN (0)) AND (`SiteTree_Live`.SubsiteID IN (0)) ORDER BY Sort You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Show = Standard) AND (`SiteTree_Live`.ClassName IN ('PersonsPage')) AND (`SiteT' at line 1
GET /ss/new-personsholder/Line 394 in C:\wamp\www\ss\sapphire\core\model\MySQLDatabase.php
What am I doing wrong? (I did run db/build several times)
-
Re: custom controller doesn't work, why?

6 April 2009 at 8:36pm
I don't fully understand what you're trying to do, but your problem is with the "Show = Standard" in the controller.
Can you post your PersonPage class code? Just the bit where you do the enum.
-
Re: custom controller doesn't work, why?

7 April 2009 at 9:17pm Last edited: 7 April 2009 9:17pm
The filter clause in DataObject::get is raw SQL, so you should replace that call with:
return DataObject::get("PersonsPage","`Show` = 'Standard'");
Note however that this will return every object (in the form of a DataObjectSet) of type 'PersonsPage' where the column 'Show' equals 'Standard'.. which might not be your intention.
| 926 Views | ||
|
Page:
1
|
Go to Top |



