So i'm creating a PerfexCRM module that will be showing customer card transactions.
I'm trying to create the basics of the module before integrating API.
My problem is I get 404 page not found every time I try to access the client module front page cardportal_client/view_transactions. I can upload the plugin and activate it, but get an error when I try to access the link via the client front.
My file structure:
assets
-js
-css
cardportal.php
controllers
- Cardportal_client.php
- cardportal_admin.php
helpers
language
- English
- cardportal_lang.php
- other_languages
models
- cardportal_model.php
views
- client_view.php
My cardportal.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
* Module Name: Card Portal
* Description: A module for clients to view their card transactions in a grid view with filters.
* Version: 1.0.0
* Requires at least: 2.3.*
*/
// Example of adding a simple hook (if needed)
hooks()->add_action('admin_init', 'cardportal_init_menu_items');
hooks()->add_action('clients_init', 'cardportal_init_client_menu');
function cardportal_init_client_menu() {
if (is_client_logged_in()) {
add_theme_menu_item('cardportal-menu', [
'name' => 'Card Transactions',
'href' => site_url('cardportal_client/view_transactions'), // Updated to the new method
'position' => 10,
]);
}
}
function cardportal_init_menu_items() {
// Code to add menu items if necessary
}
$CI =& get_instance();
// Loading a custom library or helper if necessary
// $CI->load->library('cardportal/library_name');
cardportal_model.php:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Cardportal_model extends App_Model {
public function get_transactions() {
// Example function to get data
return $this->db->get(db_prefix() . 'transactions')->result_array();
}
}
Cardportal_client.php:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Cardportal_client extends Clients_controller {
public function __construct() {
parent::__construct();
// This ensures that only logged-in clients can access this controller
}
public function view_transactions() {
$data['title'] = 'Card Transactions';
$data['transactions'] = $this->get_client_transactions(); // Assume this method fetches transactions
$this->data($data);
$this->view('client_view'); // This view should be set up to display the transactions
$this->layout();
}
private function get_client_transactions() {
// For now, let's return a static array for display
return [
['date' => '2021-01-01', 'amount' => '$100', 'description' => 'Transaction 1'],
['date' => '2021-01-02', 'amount' => '$200', 'description' => 'Transaction 2'],
['date' => '2021-01-03', 'amount' => '$300', 'description' => 'Transaction 3'],
];
}
}
client_view.php:
<div class="container">
<h2>Card Portal</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php if (!empty($transactions)): ?>
<?php foreach ($transactions as $transaction): ?>
<tr>
<td><?= htmlspecialchars($transaction['date']); ?></td>
<td><?= htmlspecialchars($transaction['amount']); ?></td>
<td><?= htmlspecialchars($transaction['description']); ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="3" class="text-center">No transactions found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
I have also added this line to the routes.php
/**
* custom plugin
*/
$route['cardportal_client/view_transactions'] = 'cardportal_client/view_transactions';