Status
Not open for further replies.

CK13

Active Member
989
2011
252
5
I have the following function used by this cms https://github.com/FoolCode/FoOlSlide:
Code:
    public function search()    {
        if (!$this->input->post('search'))
        {
            $this->template->title(_('Search'), get_setting('fs_gen_site_title'));
            $this->template->build('search_pre');
            return TRUE;
        }




        $search = HTMLpurify($this->input->post('search'), 'unallowed');
        $this->template->title(_('Search'));




        $comics = new Comic();
        $comics->ilike('name', $search)->limit(20)->get();
        foreach ($comics->all as $comic)
        {
            $comic->latest_chapter = new Chapter();
            $comic->latest_chapter->where('comic_id', $comic->id)->order_by('created', 'DESC')->limit(1)->get()->get_teams();
        }




        $this->template->set('show_sidebar', TRUE);
        $this->template->set('search', $search);
        $this->template->set('comics', $comics);
        $this->template->build('search');
    }


The line $comics->ilike('name', $search)->limit(20)->get(); searches for the name of the post/manga, but i want to be able to search in other fields too (author for example).
How can i achieve that?
And can someone explain what the "->" in the above code does, or give me a link where it is explained?
 
2 comments
Hi,

What you see there is Object Oriented programming. There is a Class by the name of "Comic". In order to access the "ilike" member function within the Comic Class, an object "$comics" was created. Using this object, the "ilike" member function was called.

If you pay attention to the arguments supplied to the "ilike" function, you will notice that you could probably replace "name" with a different column name from the table and it should work. So, for example, if you wanted to search for "age" instead of "names" and the ages are mentioned under the column "ages" within the table, you would replace:

$comics->ilike('name', $search)->limit(20)->get();
like:
$comics->ilike('ages', $search)->limit(20)->get();

You might need to look into the source code further to investigate more for further changes required. However, by the looks of it, limit(20) probably limits the number of records retrieved from the database and get() executes the request.

For further understanding of the concepts, you might refer to this tutorial: Object Oriented Programming in PHP

Regards,
-Paralytic S.J.
Plugin Development,
Neembuu
 
The part with replacing name with the column i want to search i had figured out.
Was hoping for an easy way to add another column by modifying the above function.


Thanks for the answer and the link will check it out.

LE: solved.
 
Last edited:
Status
Not open for further replies.
Back
Top