控制器不会加载模型

时间:2017-05-16 03:26:04

标签: php class

我相对较新,我正在制作一个页面使用MVC模式,所以,我创建了我的index.php,数据库,usersmodel,standardcontroller和usersctrl,从std扩展,工作正常,但是当我添加更多控制器时(所有使用基本的crud功能)它破了,现在它只显示:

model = new Users(); }}

致命错误: Class' UsersController'在第13行的C:\ xampp \ htdocs \ project \ index.php中找不到

我无法弄清楚我需要改变什么

这是我的档案。

的index.php

    if (!isset($_GET['ctrl'])){
    $_GET['ctrl'] = 'index';
}
switch($_GET['ctrl']){
    case 'index':
        echo "No hagas nada";
        break;
    case 'usuarios':
        // cargar el archivo de users controllers
        require_once('controllers/UsersController.php');
        // crear objeto
        $controller = new UsersController();
        break;
    case 'tutoriales':
        // cargar el archivo de users controllers
        require_once('controllers/TutorialsController.php');
        // crear objeto
        $controller = new TutorialsController();
        break;
    default:
        echo "El controlador seleccionado no es valido";
    $controller->ejecutar();
}

UserController.php

require_once('Controller.php');

class UsersController extends Controller {

public $model;

public function __construct(){
  parent::__construct();

  require_once('./models/Users.php');

  private static $this->model = new Users();
}

}

Controller.php这样

class Controller{

public function __construct(){

}

public function ejecutar(){
  if (!isset($_GET['act']))
  {
    $_GET['act'] = 'read';
  }
  switch($_GET['act'])
  {
    case 'read':
      $this->read();
      break;
    case 'create':
      $this->create();
      break;
    case 'update':
      $this->update();
      break;
    case 'delete':
      $this->delete();
      break;
    default:
      echo 'Acción no reconocida';
  }
}// TERMINA FUNCION EJECUTAR
public function create(){
  echo json_encode($this->model->Create());
}
public function read(){
  //echo 'Este debe listar los productos';
  echo json_encode($this->model->Show());
}
public function update(){
  //echo 'Este debe listar los productos';
  echo json_encode($this->model->Update());
}
public function delete(){
  //echo 'Este debe listar los productos';
  echo json_encode($this->model->Delete());
}

users.php(模型)

include_once('c:/xampp/htdocs/ForoCucei/foro-cucei-api/Database.php');

class Users {

function __construct(){
  $this->connection = DataBase::connection();
}

//function SignUp($data){
  //return $this->db->insert('users', $data);
//  return $this->db->insert('users', $data);
//}
function Show(){
  $st = $this->pdo->prepare('SELECT * FROM users');
  $st->execute();
  $result = $st->fetchAll(PDO::FETCH_OBJ);
  return $result;
}
function Create(){
  $name = 'Tony';
  $last = 'Stark';
  $nick = 'Ironman';
  $mail = 'Stark@mail.com';
  $pass = '+Carlos1';
  $passHash = password_hash($pass, PASSWORD_BCRYPT);
  $st = $this->pdo->prepare('INSERT INTO users(name, last, nick, mail, pass) VALUES (:name, :last, :nick, :mail, :pass)');
  $st->bindValue(":name", $name);
  $st->bindValue(":last", $last);
  $st->bindValue(":nick", $nick);
  $st->bindValue(":mail", $mail);
  $st->bindValue(":pass", $passHash);
  $st->execute();
  $result = $st->fetchAll(PDO::FETCH_OBJ);
  return $result;
}
function Update(){
  $id = 2;
  $name = 'Kimi';
  $last = 'Raikkonen';
  $nick = 'iceman';
  $mail = 'iceone@mail.com';
  $st = $this->pdo->prepare('UPDATE users
    SET `name` = :name,
        `last` = :last,
        `nick` = :nick,
        `mail` = :mail
    WHERE `iduser` = :id
  ');
  $st->bindValue(":id", $id);
  $st->bindValue(":name", $name);
  $st->bindValue(":last", $last);
  $st->bindValue(":nick", $nick);
  $st->bindValue(":mail", $mail);
  $st->execute();
  $result = $st->fetchAll(PDO::FETCH_OBJ);
  return $result;
}
function Delete(){
  $id = 3;
  $st = $this->pdo->prepare('DELETE FROM users WHERE `iduser` = :id');
  $st->bindValue(":id", $id);
  $st->execute();
  $result = $st->fetchAll(PDO::FETCH_OBJ);
  return $result;
}
}

其他型号和ctrls是这个的副本,我回应json作为我的朋友将这个连接到前端

0 个答案:

没有答案