Hello,
I'm trying to understand a logic but I'm maybe far far away...
In my previous tutorials I learned to create an object by using a specific class.
Something like :
PHP Code:
<?php
class Member
{// BEGINING OF THE CLASS
//ATTRIBUTES
protected $_MEMBER_ID,
$_MEMBER_EMAIL,
//HYDRATATION
public function hydrate(array $donnees)
{
foreach ($donnees as $key => $value)
{
$method = 'set'.ucfirst($key);
if (method_exists($this, $method))
{
$this->$method($value);
}
}
}
//CONSTRUCTEUR
public function __construct(array $donnees)
{
$this ->Hydrate($donnees);
}
//GETTERS
public function MEMBER_ID() { return $this->_MEMBER_ID ;}
public function MEMBER_EMAIL() { return $this->_MEMBER_EMAIL ;}
//SETTERS
public function setMEMBER_ID($MEMBER_ID) { $this->_MEMBER_ID = $MEMBER_ID; }
public function setMEMBER_EMAIL($MEMBER_EMAIL) { $this->_MEMBER_EMAIL = $MEMBER_EMAIL; }
} // END OF THE CLASS
?>
I've tried to create that class in the library and autoload it.
I have this error :
An uncaught Exception was encountered
Type: TypeError
Message: Argument 1 passed to Member::__construct() must be of the type array, none given, called in /Applications/MAMP/htdocs/WWW/Clickandsend/system/core/Loader.php on line 1292
Filename: /Applications/MAMP/htdocs/WWW/Clickandsend/application/libraries/Member.php
Line Number: 35
Backtrace:
File: /Applications/MAMP/htdocs/WWW/Clickandsend/application/controllers/SignUpController.php
Line: 7
Function: __construct
File: /Applications/MAMP/htdocs/WWW/Clickandsend/index.php
Line: 315
Function: require_once
Maybe I'm wrong to try to 'hydrate' my object and I need to make it another way.
I've tried to remove the construct function and create in the MemberModel and call it from the controller where I have the form validation.
PHP Code:
function createmember()
{
$member = new Member([
'MEMBER_ID' => "1",
'MEMBER_NAME' => $this->input->post('InputName') ,
]);
}
Any help to guide me on the right path ?
Thank you and sorry for the beginner mistakes.
M.