You’re welcome , the thing is, if you do a basic PHP course, you learn all the basics first. And in basic PHP, there is no $user->create()
, of course. That is a Kirby method of the $user class which is defined in the user.php
like this:
(This is just to demonstrate a bit how this stuff is all connected, pls. don’t get scared away … )
static public function create($data = array()) {
// sanitize the given data for the new user
$data = static::sanitize($data, 'insert');
// validate the dataset
static::validate($data, 'insert');
// create the file root
$file = kirby::instance()->roots()->accounts() . DS . $data['username'] . '.php';
// check for an existing username
if(file_exists($file)) {
throw new Exception('The username is taken');
}
// create a new hash for the password
if(!empty($data['password'])) {
$data['password'] = password::hash($data['password']);
}
static::save($file, $data);
// return the created user project
return new static($data['username']);
}
This function, in turn, uses a lot of other functions, which are defined elsewhere in the Kirby core, e.g. a static function called “sanitize”.
If you then look at the static sanitize function just above the user create function,you will find this bit of code:
static public function sanitize($data, $mode = 'insert') {
// all usernames must be lowercase
$data['username'] = str::slug(a::get($data, 'username'));
// return the cleaned up data
return $data;
}
Again, there are other functions used here: str::slug
and a::get
which are defined in the Kirby toolkit. The str-thingy is a string manipulation function, and a::get for working with arrays.
Now, if you are still with me on this expedition, you can go visit the Kirby toolkit /kirby/toolkit/lib
, where you will find the array methods in a.php
and the string methods in str.php
. And that’s where we finally find more basic PHP …