Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best method for implementing two dashboards and one main page
  • Hi there,

    I'm a beginner at PHP and MVC architecture. This question is regarding best practice. I want to create a system which has two dashboards along with a main page. One dashboard will be for administrators and the other for regular members. The main page will show the same content irrespective of whether the user is logged in as an administrator or as a regular member or as a guest.

    The only thing that would change on the main page would be the link to the dashboard. If user is logged as administrator, it will take him to the administrator dashboard and if as a regular member, it would take him to the member dashboard. If the user is logged in as an administrator, he should not be able to access the member dashboard and vice versa.

    My question is related to showing the link for the dashboard on the main page. The following is what I believe to be relevant to the question:

    1. Controllers: controller/admin.php, controller/member.php, controller/main.php
    2. Views: main/index.php
    3. I'm using 'SimpleAuth'.

    I was in the middle of adding an 'if' statement to the view/main/index.php when I realized there has to be a better way to do this. So I'm wondering, is there?
  • HarroHarro
    Accepted Answer
    There are many ways to solve this, and i don't think there is one single "best practice".

    Most of it depends on how modular and separated you want things to be, how complex you want to make it, how big the application is, how many people work on it, how long do you need to support it, etc.

    Assuming you have different controllers, and you want to re-use views and view components, i suggest you look at http://fuelphp.com/docs/general/views.html, the section "nested views". If you want to take it a step further, check out the Theme class. It allows you to split the view into different sections, so your member contract can insert a member dashboard view, and your admin controller can insert an admin dashboard view.
  • Alhamdulillah, I managed to solve this by modifying the Main_Controller. It is now:

    class Controller_Main extends Controller {

    private $user_group_id = 1;
    private $admin_group_id = 100;

    public function action_index() {
    if (Auth::check()) {
    $view = View::forge('main/index');

    if (Auth::member($this->user_group_id)) {

    $view->user_type = 'member';

    return $view;
    }
    elseif (Auth::member($this->admin_group_id)) {
    $view->user_type = 'admin';

    return $view;
    }
    }
    else return Response::forge(View::forge('main/index'));
    }

    public function action_404() {
    return Response::forge(Presenter::forge('main/404'), 404);
    }

    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion