-
Notifications
You must be signed in to change notification settings - Fork 0
Filter
Arnun edited this page Dec 29, 2016
·
2 revisions
In this Filter, Assume We have 2 models.
- Model Book
- Model Category
- Each book can have one category
More detail, look at Relation
Argument: ($id :int)
Return: OOB Object
Example: Get item from Class, Much like ->readAction($id); But It's return object.
$book = \MyProject\Model\Book::find(5);
echo $book->title;For Relation instead return just foreign id, Now Make it return object
class Book
{
...
public function getCategory() {
return Category::find($this->category_id);
}
public function setCategory($category_id) {
$this->category_id = $category_id;
}
}And when display, You can call column from foreign key
$book = new Book();
echo $book->getCategory()->name;Argument: ($column :string, $operator :string, $keyword :string, $reversed :bool, $limit :int)
Return: OOB Object
$categories = \MyProject\Model\Category::findBy('name', '=', 'science');
foreach ($categories as $category) {
echo $category->name;
}Argument: ($column :string, $keyword :string, $reversed :bool, $limit :int) Return: OOB Object It's will find item with
$categories = \MyProject\Model\Category::findLike('name', 'di');
foreach ($categories as $category) {
echo $category->name . ', ';
}Output: of 'di' : Encyclopedias, Dictionaries, Diaries,
Output of 'di%' : Dictionaries, Diaries,
Output of '%di' :