php - Clarity on Code -
just looking clarity on code.
i'm looking @ controller class, has protected variables named $grid , inside there there __construct function connect mongodb, after there code:
$this->grid = $mongo->selectdb($database)->getgridfs();
further on in in script in class , method have code
foreach ($this->grid->find() $file) {
am right in thinking foreach using first defined $this->grid being $monmgo->selectdb?
many thanks
it worth reading on php5 objects , classes __construct()
, $this
, , method call chaining basic object-oriented implementation concepts in php.
the php method calls chained in code example, means results of 1 method being passed next (from left right).
$this->grid = $mongo->selectdb($database)->getgridfs();
so code executes as:
- $mongo->selectdb($database) .. select database name ($database); presumes $mongo connected mongo object)
- now, call getgridfs() on selected database
- finally, assign results of last method call (
getgridfs()
) variable$this->grid
$this->grid
end being new mongogridfs object (based on return type of getgridfs()
.
the foreach
iterating on results of mongogridfs object find()
method mongogridfscursor.
Comments
Post a Comment