Could anybody please tell me what’s the diference between creating an object with new Model and Model::model()? For example:
$post = new Post;
$post2 = Post::model();
How are $post and $post2 any diferent?
Thanks
Could anybody please tell me what’s the diference between creating an object with new Model and Model::model()? For example:
$post = new Post;
$post2 = Post::model();
How are $post and $post2 any diferent?
Thanks
This
$post1 = new Post;
$post2 = new Post;
$post3 = new Post;
creates 3 different instances of an object.
This
$post1 = Post::model();
$post2 = Post::model();
$post3 = Post::model();
creates only one instance of an object to where the other variables point.
yodel
$post = new Post;
With this call you create a new instance of the Post object. So every public property/function in this class is available via $post->something.
But you couldn’t do something with e.g. ActiveRecord like find() with this class cause it is only a “normal” class.
$post = new Post::model();
With this call you create an ActiveRecord instance which is "useless" in this form until you call an AR function like find(), findAll() or findByPk().
Read the capture AR - Reading Record in the guide.
Edit: …and of course yodel’s description
yodel, kokomo, thank you. Very helpful.