Reputation: 21
Please, I am working on a WHMCS custom page, but getting errors. I want to display data from a table - I am using the clients' table as a reference. I will be grateful to get assistance.
If I remove the table part of the tpl code, the other part displays correctly.
The codes used are below:
currentmembers.php
<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Bank Statement');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('bankstatement.php', 'Bank Statement');
$ca->initPage();
$ca->requireLogin(); // Uncomment this line to require a login to access this page
// Check login status
if ($ca->isLoggedIn()) {
//get the logged in user id
$loggedin_user_id = $ca->getUserID(); //$_SESSION['uid'];
$client = Capsule::table('tblclients')
->where('id', '=', $loggedin_user_id)
->first();
$ca->assign('client_email', $client->email);
$ca->assign('clientName', $client->firstname);
//$data = Capsule::table('tblclients');
//->where('id', '=', $ca->getUserID())->value('firstname');
// 'pluck' was renamed within WHMCS 7.0. Replace it with 'value' instead.
//->where('id', '=', $ca->getUserID())
//->value('firstname');
/// $ca->assign('data', $data);
//GET ALL CLIENTS FROM DATABASE
$clientx = Capsule::table('tblclients')
->take(2)
->get();
$ca->assign('clientxs', $clientx);
print_r ($ca->assign('clientxs', $clientx));
} else {
// User is not logged in
$ca->assign('clientname', 'Random User');
}
$ca->setTemplate('bankstatement');
$ca->output();
And this is the template code currentmembers.tpl
<p>
Client email is: {$client_email}
</p>
<p>
Client name is: {$clientName}
</p>
<div class="table-container clearfix">
<table class="ui celled table">
<thead>
<tr><th>Name</th>
<th>Email</th>
<th>ID</th>
</tr></thead>
<tbody>
{foreach from=$clientxs item=clientx}
<tr>
<td data-label="Name">{$clientx.firstname} {$clientx.lastname}</td>
<td data-label="Age">{$clientx.email}</td>
<td data-label="Job">{$clientx.id}</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
Upvotes: 2
Views: 935
Reputation: 1584
The $clientx is an object. So you need to use the Object Operator (->) to access its properties. Dot is used with arrays. so in template code becomes:
{foreach from=$clientxs item=clientx}
<tr>
<td data-label="Name">{$clientx->firstname} {$clientx->lastname}</td>
<td data-label="Age">{$clientx->email}</td>
<td data-label="Job">{$clientx->id}</td>
</tr>
{/foreach}
Upvotes: 0