for each loop

cobra959

Member
I am trying to pass db info to a template, I have read the tut on reading and writing from the database - simpletext. I don't understand how the variable "$simpleText" was used in the for each loop. Is this variable defined in the controller or model?

<xen:foreach loop="$simpleText" value="$text">

Thanks for the help.
 
Generally speaking, the controller passes the variables to the templates in the response parameters. That variable can then be used in the template. You will have to show the full code for anyone to give you a more specific answer.
 
I seem to be stuck again within my for each loop, I don't have the error anymore for my arry but it will not display anything within the page.

//code within my Model class
public function getAllProcessors()
{
$rows = $this->fetchAllKeyed("SELECT * FROM `xf_api` ORDER BY `api_title` ASC", 'api_id');
$i = 0;
$values = array();
foreach($rows as $value)
{
$values[$i]['api_id'] = $value['api_id'];
$values[$i]['api_title'] = $value['api_title'];
$values[$i]['api_active'] = $value['api_active'];
$values[$i]['api_currency'] = $value['api_currency'];
$values[$i]['api_recurring'] = $value['api_recurring'];
$i++;
}
return $values;
}

//controller actionIndex...
public function actionIndex()
{
$viewParams = array( 'api' => $this->_getModel()->getAllProcessors() );
return $this->responseView('API_ViewAdmin_API', 'api', $viewParams);
}

//template
<xen:title>{xen:phrase api_title}</xen:title>

<xen:require css="filter_list.css" />
<xen:require js="js/xenforo/filter_list.js" />

<h2 class="subHeading">
{xen:phrase api_header}
</h2>

<ol class="FilterList">
<xen:foreach loop="$api" value="$payments">
<xen:listitem
id="{$payments.api_id}"
label="{$payments.api_title}">
</xen:listitem>
</xen:foreach>
</ol>

I am trying to create a admin api option list, to allow a checkbox to activate or deactivate the api.

EDIT:
ok i can display my data now. template name error lol
 
Top Bottom