HI.
i tried to create my first own modell and controller,
in "Controller/My/Dashboard"
"
Code:
namespace App\Controllers\My;
use App\Controllers\BaseController;
//Load needed Models
use App\Models\Model;
class Dashboard extends BaseController
{
//Load Models, Helpers etc.
public function __construct()
{
$this->UsersModel = model('UserModel');
//$this->someModel = model('Some_model');
}
public function index()
{
//Get ID of loggedin user
$user = auth()->user();
//get all datas from user-table
$data['user'] = $this->UsersModel->users_get_by_id(user_id());
echO"<pre>";
var_dump($user);
die("Stopp");
}
}
"
in my model App/Models/UserModel.php
Code:
namespace App\Models;
use CodeIgniter\Model;
//use CodeIgniter\Database\Exceptions\DataException;
/**
* @phpstan-consistent-constructor
*/
class UsersModel extends Model
{
//DB Connection - default is globalDB
protected $DBGroup = 'globalDB';
/**
* Called during initialization. Appends
* our custom field to the module's model.
*/
protected function initialize()
{
//Mdoell DB-Table
protected $table = 'users';
$this->table = $this->tables['users'];
//Modell DB-Tables primary key
protected $primaryKey = 'id';
...
}
public function users_get_by_id(int $id)
{
return $this->find($id);
}
}
If i enter the "my/dashboard" page, i revieved this error: "Call to undefined method CodeIgniter\Shield\Models\UserModel::users_get_by_id "
I wondering about the path, why "Shield"?
In the NAmespaces of the Controller and the Modell i told "App" Path?
What i do wrong?
Sorry i find the problem,
Shield has a model called "user Model", in my dashboard I called this "usersModel" instead of my own - I forgot the "s", that's all
Now i have new problem: "Type of App\Models\UsersModel::$allowEmptyInserts must be bool (as in class CodeIgniter\BaseModel) " what it means? What i have to do?
for them moment i comment out the line "$allowEmptyInserts" that all, but i think it will be better to understand what $allowEmptyInserts is for ;-)