Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

Dynamic Letter Filter for a Kohana Controller Object

Olivia Rhye

Basically this is done with the "like" limiting SQL command. In Kohana, looking for users with names beginning with an "a" would be:

ORM::factory('user')->where('name','LIKE',"a%")->find_all();

So we made a dynamic function in the controller that would retreive the users of a given letter.

$users = ORM::factory('company')->getUsers($letter);

This function can be placed in the the model of the controller, "$letter" can also be a substring:

public function getUsers($letter = '')
{
$letter = $letter."%";
if($letter==""){
$returnObj = ORM::factory('user')->find_all();
}
else{
$returnObj = ORM::factory('user')->where('name','LIKE',$letter)->find_all();
}
return $returnObj;
}

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy