Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

custom controller doesn't work, why?


Reply


3 Posts   1118 Views

Avatar
theAlien

Community Member, 131 Posts

24 March 2009 at 6:14am

Edited: 24/03/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 [url=http://www.silverstripe.org/archive/show/181525#post181525]this post[/url] 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)

Avatar
david_nash

Community Member, 55 Posts

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.

Avatar
Hamish

Community Member, 712 Posts

7 April 2009 at 9:17pm

Edited: 07/04/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.