CodeIgniter Forums
Simple question about instances and stuff - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Simple question about instances and stuff (/showthread.php?tid=49601)



Simple question about instances and stuff - El Forum - 02-26-2012

[eluser]Unknown[/eluser]
Hello!
Let's assume I have a Class that creates instances of users.
Certain type of users are allowed to post information through a form and I need to keep the instance of that user and a record of who poste what.

For example:

<code>
Class Post
{
var $user_id = 0;

function __construct($id)
{
$this->user_id = $id;
}

function create_post(){

does stuff ...

}

}


Class User
{

var $user_id = 0;
var $user_type = 0;

function __construct($id, $type)
{
$this->user_id=$id;
$user_type=$type;
}

function login()
{
...do things
$this->load->view(...some view containing the user profile layout);
}

function create_new_post(){

$post = new Post($this->user_id);
$post->create_post();

}

}


class Login extends CI_Controller{

code ... bla-bla

function validate_login(){
...id and type are given, validation is successful
$user= new User($type,$id);
$user->login();
}
}
</code>
now after the $user->login() i am sent to a view with a menu and stuff.
My question was ... can i somehow keep (or pass) the instance of the newly created user so that i can call the "create_new_post()" as an anchor? - base_url('/user/create_new_post')


I'm not sure if it's clear what I want ... but I hope you understand.

Thank you!