This repository contains a simple application built using the CodeIgniter framework, which follows the Model-View-Controller (MVC) design pattern.
To get the application up and running, follow these steps:
- Clone the repository:
git clone https://github.com/ramin123/systemMVC.git
- Navigate to the project directory:
cd your-repository
- Set up the database and configure the
application/config/database.php
file. - Run the application on your local server.
The project is structured as follows:
your-repository/
|-- application/
| |-- config/
| |-- controllers/
| |-- models/
| |-- views/
| |-- ...
|-- system/
|-- public/
| |-- css/
| |-- js/
| |-- index.php
|-- .htaccess
|-- README.md
Models contain the logic for interacting with the database. Here's an example model:
class ProductModel extends CI_Model {
public function get_products() {
// Code to retrieve products from the database
$query = $this->db->get('products');
return $query->result();
}
}
Views are responsible for displaying the data to the user. Here's an example view:
<!-- View file: application/views/products_view.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Products List</title>
</head>
<body>
<h1>Products</h1>
<ul>
<?php foreach ($products as $product) : ?>
<li><?php echo $product->name; ?> - <?php echo $product->price; ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
Controllers act as an intermediary between models and views. Here's an example controller:
class Products extends CI_Controller {
public function index() {
$this->load->model('ProductModel');
$data['products'] = $this->ProductModel->get_products();
$this->load->view('products_view', $data);
}
}
To access the application, navigate to the URL corresponding to the controller's class and method, such as http://localhost/index.php/products
.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.