Jump to content

OOP MVC Admin Area


like_to_code

Recommended Posts

Hi, I am new here 🙂

I have been learning PHP and am currently working on my own OOP MVC CMS.  I am up to the stage where I would like to start working on the admin area, but I am not sure how best to organise things.

Should I create admin specific Controllers and Models?

In Views, should I create a sub directory Admin, and place all admin view templates within it?

Are there any good books on OOP/MVC you would recommend?

 

 

 

Link to comment
Share on other sites

9 hours ago, like_to_code said:

Should I create admin specific Controllers and Models?

Controllers drive views, so if there are admin views then you'll probably want one or more admin controllers.

Models are mostly for database tables, so if there are admin tables then you'll want admin models.

9 hours ago, like_to_code said:

In Views, should I create a sub directory Admin, and place all admin view templates within it?

If that's similar to how you're arranging the rest of the views in your application then continuing to do so sounds like a good idea.

Link to comment
Share on other sites

Thanks for the reply, it's good to know what I have been doing is ok.

I have organised things like this so far:

For example:
Controllers/Backend/Home.php
Controllers/Frontend/Home.php
Models/Pagination.php
Views/Backend/Admin/Home/index.php
Views/Frontend/Home/index.php
Core/Controller.php
public/backend/css
public/frontend/css
public/index.php

In the Router.php dispatch method, where it matches the url, I added the following:

if (preg_match('/^(admin)/', $url)) {
	$this->setLocation('backend');
} else {
    $this->setLocation('frontend');
}

So if admin is mentioned at the start of the url, it sets the location to 'backend', which is then used in Router.php.  It was the simplest solution I could think of.

$controller = $this->getLocation() . '\\' . $this->params['controller'];
$controller = $this->convertToStudlyCaps($controller);
$controller = $this->getNamespace() . $controller;

Things seem to be working ok and I have started adding features to the Frontend and Backend side of the CMS.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.