mysql - PHP OOP - best way to implement 2 classes -


I have a simple DB with user data table, controller data table and user controller table, which contains the controller ID and userId.

In my PHP OOP (first time) implementation I have a Class User and a Class Controller.

The functionality is simple for the user - he can login and logout all its controllers I have an admin user who can see all users and their controllers, add / remove the controller to a user / Can edit and add users \ delete \ edit / add / add / edit users.

Login functionality has been applied (DB class), user class and auxiliary class)

My problem is how to add user and controller, I should create the functionality . The administrator has an ID (unique), a name (not unique) and a password.

Users are private areas:

  private $ _ db, $ _data, // all this user data $ _sessionName, $ _cookieName, $ _isLoggedIn;   

and control class:

  private $ _ db, $ _data; // I have tried to implement the controller:  
  create public functions ($ fields = array ()) {if (! $ $-> Enter-> _db- & gt; ('Controller', $ field)) {New Exception ("Problems Creating New Controller");}}   

Function createController user:

  public function addController ($ pass, $ controller_name, $ lat = '', $ lon = '') {if ($ pass & amp; $ controller_name) {$ Controller = new controller (); $ Salt = hash :: salt (32); $ Controller- & gt; Make (Array ('pass' = & gt; hash :: make ($ pass, $ salt), 'salt' = & gt; $ salt, 'admin_name' = & gt; $ controller_name, 'lat' = & gt; $ Axis, 'loan' = & gt; $ lon); // If we succeed then user-controller table $ controller_modern = $ controller- & gt; Find ($ controller_name) - & gt; Data () - & gt; Id; $ UserID = $ this- & gt; Data () - & gt; Id; $ Fields = array ('UserID' = & gt; $ userID, 'Admin ID' = & gt; $ controller_id); If (! $ This-> _db- & gt; Insert ('user_controllers', $ fields)) {New Exception ("Problems Creating Controller for User"); }} Hold (exception $ e) {new exception throw ('there was a problem creating new controller'); }} And {throw a new exception ('no name or password was given'); }   

Generally it is working but there are some problems:

  1. The ID of the controller is automatically created by DB so I I do not know when I create it, I can find the name later by the name because I can have many controllers with this name

  2. I'm not sure whether this user and The correct way to handle the relationship between the controller is

  3. I I have trouble applying "Show all my controllers".

    Can you please tell me what is the correct way to apply this relationship and how to To create controllers and showcontrollers?

    Your structure looks correct.

    Resolve your problems:

          Li>

          When you insert data, you will have to retrieve the entered ID of the new record in order to use it in your mapping relationship. I am not sure in your example if you have written this MVC structure yourself or otherwise; This code looks slightly like an ignitioner if it is a CI application, if it is a bespoke application, you can use it or

        1. what are you doing correct.

        2. In a "show all your controllers" user scenario, you will ask the user_controller table to get a list of all the control relationships, and you can join Compulsions can be easily inserted to join). You specify that you have controller in your selected areas * , and you will end up with a record for each controller and ignore the user control field (if you do not need them). An example SQL query might look like this:

           SELECT controller. * Log on to the controller on UC Inner controller from user controller User = user_controller.controller_id WHERE user_controller.user_id = [YOUR_USER_ID_HERE]     

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -