در این آموزش میخواهیم افزودن دستی Create a Custom Dashboard Module یک مدل یا ماژول به قسمت صفحه اصلی پنل ادمین با موضوع آخرین مشتری های عضو شده recentcustomers را قرار دهیم.
برای شروع به قسمت admin/controller/dashboard/recentcustomers.php بروید و در یک فایل recentcustomers.php را اضافه منید.
سپس کد زیر را در داخل فایل کپی کنید.
<?php
class ControllerDashboardRecentcustomers extends Controller {
public function index() {
$this->load->language('dashboard/recentcustomers');
$data['heading_title'] = $this->language->get('heading_title');
$data['column_customer_id'] = $this->language->get('column_customer_id');
$data['column_customer_name'] = $this->language->get('column_customer_name');
$data['column_customer_email'] = $this->language->get('column_customer_email');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['recentcustomers'] = array();
$this->load->model('report/recentcustomers');
$results = $this->model_report_recentcustomers->getRecentCustomers();
foreach ($results as $result) {
$data['recentcustomers'][] = array(
'customer_id' => $result['customer_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'email' => $result['email'],
'date_added' => $result['date_added']
);
}
return $this->load->view('dashboard/recentcustomers.tpl', $data);
}
}
این یک تنظیم کنترلر نسبتاً ساده است! نکته مهمی که باید در اینجا ذکر شود اینست که ما در حال بارگیری مدلم شتری های اخیر هستیم و از روش getRecentCustomers برای واکشی مشتریان اخیر استفاده می کنیم.
در این مرحله کد زبان را در آدرس admin/language/english/dashboard/recentcustomers.php اضافه و در فایل محتویات زیر را قرار میدهیم.
<?php
// Heading
$_['heading_title'] = 'Recent Customers';
// Text
$_['column_customer_id'] = 'Customer ID';
$_['column_customer_name'] = 'Customer Name';
$_['column_customer_email'] = 'Customer Email';
$_['column_date_added'] = 'Date Added';
$_['text_no_results'] = 'No customer(s) found.';
مجدد در آدرس admin/model/report/recentcustomers.php فایل recentcustomers.php ایجاد و محتویات زیر را در آن کپی میکنیم.
<?php
class ModelReportRecentcustomers extends Model {
public function getRecentCustomers() {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` ORDER BY date_added DESC LIMIT 5");
return $query->rows;
}
}
برای نمایش در قالب این مرحله ضروری می باشد و شاخه admin/view/template/dashboard/recentcustomers.tpl را ایجاد و کد زیر را در آن کپی کنید.
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-users"></i> <?php echo $heading_title; ?></h3>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<td class="text-right"><?php echo $column_customer_id; ?></td>
<td><?php echo $column_customer_name; ?></td>
<td><?php echo $column_customer_email; ?></td>
<td><?php echo $column_date_added; ?></td>
</tr>
</thead>
<tbody>
<?php if ($recentcustomers) { ?>
<?php foreach ($recentcustomers as $customer) { ?>
<tr>
<td class="text-right"><?php echo $customer['customer_id']; ?></td>
<td><?php echo $customer['name']; ?></td>
<td><?php echo $customer['email']; ?></td>
<td><?php echo $customer['date_added']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="6"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
حالا وقت اضافه کردن این مدل برای نمایش در داشبورد رسیده که با رفتن به قسمت admin/controller/common/dashboard.php و باز کردن و ادیت آن کد زیر را پیدا
$data['recent'] = $this->load->controller('dashboard/recent');
سپس این کد را بعد از این خط اضافه کنید:
$data['recentcustomers'] = $this->load->controller('dashboard/recentcustomers');
آخرین مرحله افزودن نوع نمایش این ماژول تم و داشبورد میباشد که به طریق زیر انجام می شود.
به قسمت admin/view/template/common/dashboard.tpl بروید و خط <div class="col-lg-8 col-md-12 col-sm-12 col-sx-12"><?php echo $recent; ?></div> پیدا کنید و کد زیر را بعد از آن اضافه کنید.
<div class="col-lg-8 col-md-12 col-sm-12 col-sx-12">
<?php echo $recentcustomers; ?>
</div>
حالا ماژول
Recent Customers شما دقیقا مانند شکل زیر نمایش داده می شود.
create-a-dashboard-module-in-opencart-recent-customers-block.png