3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 200 Views |
-
DataList byIDs ensure value is an array?

15 November 2012 at 1:40am Last edited: 15 November 2012 1:45am
I have a Text field called selecetdIndividuals on Page Table. eg: 18,19,20
I want to use it to show the chosen Individuals which are in my Individuals table.
in my Page.php if manually set the values it works.
if try and make it dynamic its doesn't,, but i have echoed $selectedIndividuals and they display.public function SelectedStaff($selectedIndividuals) {
if ($selectedIndividuals) {// comment out $idList = new Array($selectedIndividuals);
//manually set
$idList = array(18,19,20);
$dl = DataList::create('Individual')->byIDs($idList);
return $dl;
} else {
echo "non some values are null like this one";
}
}so what i mean is when i do $idList = $selectedIndividuals; i get an error
[Warning] array_map(): Argument #2 should be an array
Line 781 in /home/hmyapp/public_html/framework/model/DataList.php
773
774 /**
775 * Filter this list to only contain the given Primary IDs
776 *
777 * @param array $ids Array of integers, will be automatically cast/escaped.
778 * @return DataList
779 */
780 public function byIDs(array $ids) {
781 $ids = array_map('intval', $ids); // sanitize
782 $baseClass = ClassInfo::baseDataClass($this->dataClass);
783 $this->where("\"$baseClass\".\"ID\" IN (" . implode(',', $ids) .")");
784
785 return $this;
786 } -
Re: DataList byIDs ensure value is an array?

15 November 2012 at 2:58am
this was the bit i needed
$idList = explode(',',$selectedIndividuals);//function to display selected individuals on the frontend
public function SelectedStaff($selectedIndividuals) {if ($selectedIndividuals) {
//turn the passed string 18,19,20 into an array
$idList = explode(',',$selectedIndividuals);
//get a readonly result
$dl = Individual::get()->byIDs($idList);
return $dl;
}else {
//no selected individuals passed
return;
}
}
| 200 Views | ||
|
Page:
1
|
Go to Top |

