<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[CodeIgniter结合Ajax编写搜索功能]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Thu, 22 May 2008 12:48:25 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	需要prototype.js支持。<br/><strong>function_search.js</strong><br/><textarea name="code" class="javascript" rows="15" cols="100">
window.onload = function () &#123;
 new Ajax.Autocompleter("function_name", "autocomplete_choices", base_url+'application/ajaxsearch/', &#123;&#125;);
 $('function_search_form').onsubmit = function () &#123;
&nbsp;&nbsp;inline_results ();
&nbsp;&nbsp;return false; 
 &#125;
&#125;
function inline_results () &#123;
 new Ajax.Updater ("function_description", base_url+'application/ajaxsearch', &#123;method:'post', postBody:'description=true&function_name='+$F('function_name')&#125;);
 $('function_description').hide();
 new Effect.Appear('function_description');
&#125;
</textarea><br/><strong>控制器</strong><br/><textarea name="code" class="php" rows="15" cols="100">
<?php
class Application extends Controller &#123;
 function Application()
 &#123;
&nbsp;&nbsp;parent::Controller();
&nbsp;&nbsp;$this->load->model('function_model');
 &#125;
 function index()
 &#123;
&nbsp;&nbsp;$data['title'] = "Code Igniter Sample Application";
&nbsp;&nbsp;$data['extraHeadContent'] = '<script type="text/javascript" src="' . base_url() . '/js/function_search.js"></script>';
&nbsp;&nbsp;$this->load->view('application/index', $data);
 &#125;
 function ajaxsearch ()
 &#123;
&nbsp;&nbsp;$searchTerm = $this->input->post('function_name');
&nbsp;&nbsp;$description = $this->input->post('description');
&nbsp;&nbsp;echo $this->function_model->getSearchResults($searchTerm, $description);
 &#125;
 
 function search()
 &#123;
&nbsp;&nbsp;$data['title'] = "Code Igniter Sample Application Results";
&nbsp;&nbsp;$searchTerm = $this->input->post('function_name');
&nbsp;&nbsp;$data['search_results'] = $this->function_model->getSearchResults($searchTerm);
&nbsp;&nbsp;$this->load->view('application/search', $data);
 &#125;
&#125;
?>
</textarea><br/><strong>模块</strong><br/><textarea name="code" class="php" rows="15" cols="100">
<?php
class Function_model extends Model &#123;
 function Function_model()
 &#123;
&nbsp;&nbsp;parent::Model();
 &#125;
 function getSearchResults ($function_name, $descriptions = TRUE)
 &#123;
&nbsp;&nbsp;$this->db->like('function_name', $function_name);
&nbsp;&nbsp;$this->db->orderby('function_name');
&nbsp;&nbsp;$query = $this->db->get('functions');
&nbsp;&nbsp;if ($query->num_rows() > 0) &#123;
&nbsp;&nbsp; $output = '<ul>';
&nbsp;&nbsp; foreach ($query->result() as $function_info) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;if ($descriptions) &#123;
&nbsp;&nbsp;&nbsp;&nbsp; $output .= '<li><strong>' . $function_info->function_name . '</strong><br />';
&nbsp;&nbsp;&nbsp;&nbsp; $output .= $function_info->function_description . '</li>';
&nbsp;&nbsp;&nbsp;&nbsp;&#125; else &#123;
&nbsp;&nbsp;&nbsp;&nbsp; $output .= '<li>' . $function_info->function_name . '</li>';
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp; &#125;
&nbsp;&nbsp; $output .= '</ul>';
&nbsp;&nbsp; return $output;
&nbsp;&nbsp;&#125; else &#123;
&nbsp;&nbsp; return '<p>Sorry, no results returned.</p>';
&nbsp;&nbsp;&#125;
 &#125;
&#125;
?>
</textarea><br/><strong>视图</strong><br/><textarea name="code" class="php" rows="15" cols="100">
<?php
$this->load->view("header");
?>
&nbsp;&nbsp;&nbsp;&nbsp;<h2><?= $title;?></h2>
&nbsp;&nbsp;&nbsp;&nbsp;<div id="function_description"> 
&nbsp;&nbsp;<?= $search_results;?>
 </div>
<?php
$this->load->view("footer");
?>
</textarea><br/>Tags - <a href="https://blog.liuts.com/tags/codeigniter/" rel="tag">codeigniter</a> , <a href="https://blog.liuts.com/tags/prototype/" rel="tag">prototype</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] CodeIgniter结合Ajax编写搜索功能]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>