5121 Posts in 1527 Topics by 1119 members
| Go to End | Next > | |
| Author | Topic: | 1234 Views |
-
select form in CMS

15 January 2009 at 4:55am
hi
i'm still learning silverstripe but the documentation isn't very good for me so i have probably basic question for you
i want to add a new layer with SELECT FORM with values form database into my CMS
what is wrong ? i get empty select form
class TourPage extends Page {
static $db = array(
....
);static $has_one = array(
....
);function tour() {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
'Title'
);$sqlQuery->from = "SiteTree";
$sqlQuery->where = "ClassName = TourHolder";
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute()->result();
}function getCMSFields() {
$fields = parent::getCMSFields();....
....$fields ->addFieldToTab("Root.Content.See Also", new DropdownField('ToursList', 'Tours',$result));
return $fields;
}}
class TourPage_Controller extends Page_Controller {
} -
Re: select form in CMS

15 January 2009 at 5:16am
You're working way too hard.
function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.See Also", new DropdownField('ToursList','Tours',DataObject::get("Tour")->toDropdownMap()));
return $fields;
}not sure what this is about:
function tour() {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
'Title'
);Stay away from using the SQLQuery object directly. Stick to the ORM.
-
Re: select form in CMS

18 January 2009 at 7:02am
what is ORM ?
I want to do this SELECT title FROM tour WHERE ClassName = 'TourPage'
and result put into dropdownlist in the new tab in CMS -
Re: select form in CMS

18 January 2009 at 8:14am Last edited: 18 January 2009 8:15am
This didn't work?
new DropdownField('Tours','Tours',DataObject::get("TourPage")->toDropdownMap());
I suppose what you really want is to create a relationship to the TourPage.
static $has_one = ('SeeAlso' => 'TourPage');
$fields->addFieldToTab("Root.Content.See Also", new DropdownField('SeeAlsoID','Tours',DataObject::get("TourPage")->toDropdownMap()));
-
Re: select form in CMS

18 January 2009 at 12:13pm
i need help again :>
ok i have the dropdownlist and to database a put value which i chose
static $db = array(
'SeeAlsoID' => 'Text'
);now i want to select other values form two tables which are connected by SeeAlsoID
SELECT Title, Content FROM SiteTree, TourPage WHERE SiteTree.ID = TourPage.SeeAlsoID
next i want to create some template for the query result
i create function
class TourPage extends Page {
static $db = array(
...
);static $has_one = array(
...
}function tour() {
...
}function getCMSFields() {
...
}function SeeAlsoData(){
$sqlQuery = new SQLQuery();
$sqlQuery->select = array('Title', 'Content');
$sqlQuery->from = "SiteTree, TourPage";
$sqlQuery->where = "SiteTree.ID = TourPage.SeeAlsoID";// get the raw SQL
$rawSQL = $sqlQuery->sql();// execute and return a Query-object
$result = new DataObjectSet();
$result = $sqlQuery->execute();
foreach($result as $row) {
$title = $row['Title'];
$content = $row['Content'];
}
return $this->renderWith("SeeAlso");
}}
in SeeAlso.ss i have
<% control SeeAlsoData %>
<p>$title</p>
<p>$content</p>
<% end_control %>in PageTour.ss i tried include template by $SeeAlso but i get "The website server has not been able to respond to your request."
-
Re: select form in CMS

18 January 2009 at 1:34pm
Once again, you're working way too hard. You shouldn't be using SQLQuery objects, and actually, none of your code is necessary. It's all built into Silverstripe.
On TourPage.ss, all you have to do is:
<% control SeeAlso %>
$Title
$Content
<% end_control %>I recommend you read tutorial #5 in the docs on DataObject management.
-
Re: select form in CMS

19 January 2009 at 2:20am Last edited: 19 January 2009 2:55am
so if i add in TourPage.php this code
static $has_one = array(
'SeeAlso' => 'SiteTree'
);i will get relationship between the TourPage table and the SiteTree table where TourPage.ID = SiteTree.ID
and if i want to get Title from SiteTree only have to do is put this code in TourPage.ss
<% control SeeAlso %>
$Title
<% end_control %>?
but id doesnt work
EDIT: it works
| 1234 Views | ||
| Go to Top | Next > |

