i am creating an admin panel in my project.
So to sepeate admin files i am creating admin folder in my views
can i also create admin folder in my controller and model.
to seperate admin related file?
is that a correct procedure?
i am creating an admin panel in my project.
So to sepeate admin files i am creating admin folder in my views
can i also create admin folder in my controller and model.
to seperate admin related file?
is that a correct procedure?
Short answer to (and thanks to for checking the MVC): CodeIgniter supports organizing admin code into subfolders for controllers, models and views. That is a common and acceptable approach — just follow CI's conventions (file/class names, loading paths and routing).
Example (CodeIgniter 3 style): put controllers under application/controllers/admin, models under application/models/admin, and views under application/views/admin. A controller might load a model and view like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('admin/User_model', 'user'); // loads application/models/admin/User_model.php
}
public function index() {
$data = $this->user->summary();
$this->load->view('admin/dashboard', $data); // loads application/views/admin/dashboard.php
}
} If using CodeIgniter 4 (different structure and namespaces), place controllers in app/Controllers/Admin and use a route group for the admin prefix:
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
class Dashboard extends BaseController {
public function index() {
return view('admin/dashboard');
}
} and in app/Config/Routes.php:
$routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function($routes){
$routes->get('dashboard', 'Dashboard::index');
}); Notes and best practices:
$this->load->model('admin/User_model','user').Official docs: Controllers — CodeIgniter 3 User Guide, Models — CodeIgniter 3 User Guide, and .
Jump to Post— DaveAmour 160Sounds like some kind of MVC architecture - is this right? If so which specific one?
Sounds like some kind of MVC architecture - is this right? If so which specific one?
yes its codeigniter, mvc
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.