Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » custom controller doesn't work, why?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1053 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    custom controller doesn't work, why? Link to this post

    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)

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: custom controller doesn't work, why? Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: custom controller doesn't work, why? Link to this post

    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.

    1053 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.