Welcome Guest, Not a member yet? Register   Sign In
using new Object();
#1

[eluser]Sherz[/eluser]
Is is possible to do this in CI:

Code:
$user = new User();
$user->load(array('id' => 0));
$user->delete();

Where the user model would look something like this:

Code:
class User extends Model
{
$var name = 'Bob';
$var pass = 'q3285saofdj09283';
function load($info)
{
}

function delete()
{
}
}
#2

[eluser]bretticus[/eluser]
Certainly, with an include statement or an autoload function in scope. The question is, why would you want to? $this->load->model() has many advantages ( easy extension of core classes, faster "include_once" logic, accessibility, etc.)
#3

[eluser]Sherz[/eluser]
I want to be able to make an instance of a class, modify it then use functions on it. Like this:

Code:
$user = new User();
$user->username = "Bob";
$user->saveToDatabase();

What would be the better way of doing something similar to this with CI?
#4

[eluser]pistolPete[/eluser]
I would use an ORM, have a look at e.g. http://codeigniter.com/wiki/ORM/ or search the Ignited Code forum.
#5

[eluser]cahva[/eluser]
Yes.. With Datamapper ORM(seems to be down atm of writing this) you would delete user like this(this is one way):
Code:
$user = new User();
$user->get_by_id($id);
$user->delete();




Theme © iAndrew 2016 - Forum software by © MyBB