Welcome Guest, Not a member yet? Register   Sign In
Tutorial (Class 'App\Models\NewsModel' not found)
#7

I am on very start of learning this grate framework, but have some problems.

I have similar problem, cant understand what is problem, can someone help please?

Model:
Location: app\Models\Main\ToolsModel.php
Code:
<?php
namespace App\Models\Main;
use CodeIgniter\Model;

class ToolsModel extends Model {
  protected $table = 'rent';
  protected $primaryKey = 'id';
  protected $returnType = 'array';
  protected $allowedFields = ['id','title','description','price_day','price_week','image'];

  function getRecords(){
    $query = $this->db->get('rent');
    return $query->result();
  }
}

Controller:
Location: app\Controllers\Main\MainController.php
Code:
<?php
namespace App\Controllers\Main;
use App\Controllers\BaseController;
use App\Models;

class MainController extends BaseController {
  public function index() {

    $db = \Config\Database::connect();
    $rentQuery  = $db->query('SELECT id, title, description, price_day, price_week, image FROM rent');
    $rentTools = $rentQuery->getRowArray();
    $rentTools = model('ToolsModel');
  return view('Main/index', $rentTools);
}

I tryed many ways for namespace and use, nothing works, in controller colored text:
Model in use App\Models; and written Undefined class 'Models'

What am i doing wrong and how to fix?
Reply


Messages In This Thread
RE: Tutorial (Class 'App\Models\NewsModel' not found) - by Jazek - 10-20-2022, 02:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB