• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to load Model?

#1
Code:
$usermodel = new \App\Models\UserModel();
Code:
$usermodel = new UserModel();
 
are they the same? which one is correct? thanks
Q&A for Codeigniter
StartBBS--open-source, light weight forum software.
Best VPS:Digital Ocean
Reply

#2
They are only the same if you have declared the model at the top of the file:

Code:
<?php  namespace App\Controllers;

use App\Models\UserModel;

class SomeController
{
    public function index()
    {
        $usermodel = new UserModel();
    }
}

Otherwise you'll get an error. If you haven't used them before, running through a quick crash course on namespaces would be very helpful.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.