Search code examples
codeigniteryui

Search feature in Code Igniter using YUI


I have a project that require me to do a auto complete search using CI and YUI. User will enter search keywords in textfield 1 and the result will shown in textfield 2..


Solution

  • YUI is client-side JavaScript. What you should do is read some documentation on autocomplete first, and on CodeIgniter second and then you could start building your solution.

    Basically, you have to make a few things.

    For one, you should create a client-side page with what is basically an <input> or <textarea> tag and a div for your results and hook a YUI autocomplete handler to that field. To be able to use YUI, you first need to include the YUI script:

    <script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
    

    And you also need to load the autocomplete module and configure it:

    YUI().use('autocomplete', function (Y) {
        // enter code here
    }
    

    Second, you need to build a server-side script with CI that will listen for queries, do database or whatever searches and return JSON or some other format of results.

    You'll then give the URL of this CI query web script to YUI AutoComplete configuration and YUI will do the AJAX and stuff for you.

    Those are very general steps, but your question is also pretty generic. If you ask more specific questions, you'll get better answers (or better, just search and read the documentation).