CodeIgniter Forums
how to create paging with form search, but query string enable?? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: how to create paging with form search, but query string enable?? (/thread-13581.html)



how to create paging with form search, but query string enable?? - El Forum - 11-28-2008

[eluser]deepydee[/eluser]
how to create paging with search, but query string enable??..


how to create paging with form search, but query string enable?? - El Forum - 11-28-2008

[eluser]JoostV[/eluser]
I'm not sure what it is you're asking for, but anyway.

By default query string (?foo=bar) is not enabled. This does not have to be a problem, though. Actually, your app is safer this way, so it's a good thing.

Now to build a search module:
1. create a controller search/redirect, that creates a string that you can use to redirect to another controller, search/result. Your search form should post to search/redirect.

Code sample for search/redirect:
Code:
if ($this->validation->search_string) {
    // Replace spaces with slashes so we get a uri to redirect to
    $uri = str_replace(' ', '/', $this->validation->search_string);
    // Redirect to the result controller, adding a segment for each search string.
    // E.g. serach/results/my/search/string
    redirect('search/results/' . $uri, 'refresh');
}
2. In your controller search/result you can fetch the search strings from the uri and perform your search.
3. You can use paging without having to store the search strings anywhere. You can always access the search strings because they are in your uri.

As an added bonus: you search will become more user-friendly because users can now:
1. search by typing serach strings in the uri instead of posting
2. deeplink to serach results, or store them in favorites


how to create paging with form search, but query string enable?? - El Forum - 12-01-2008

[eluser]deepydee[/eluser]
thanks joosv before, but i still error, like this

http://localhost/application/index.php?c=application/20

The URI you submitted has disallowed characters.

why be??


how to create paging with form search, but query string enable?? - El Forum - 12-01-2008

[eluser]JoostV[/eluser]
As I said, "By default query string (?foo=bar) is not enabled."

You need to use action post, not get


how to create paging with form search, but query string enable?? - El Forum - 12-02-2008

[eluser]deepydee[/eluser]
yes i use method post, but i still confuse to parsing that page coz my URI get in $indexx ??? , this sinopsis my script

in controler
Code:
class Application extends controler {
[b]var $indexx = "index.php?c=application";[/b]

....

function application()
    {
        parent::Controller();
        this->load->helper('url');
        $this->load->helper('date');
        $this->load->helper('form');
        $this->load->helper('string');
        $this->load->helper('file');
        $this->load->helper('html');
     }

function index()
    {
         if ($this->input->post('from') == 'registerold')
         {
            $this->registerold();
            return false;
        }
    }
function filter()
{
$kond = '';

if ($this->input->post('nomorregisterold') != '')
{          
$kond .= " AND nomorregisterold = '" . $this->input->post('nomorregisterold') . "' ";
}

.....

}

function registerold(){
  if(!$this->Loginkah())
         {
        $this->mainmenu();
        return false;
      }
$kond = $this->filter();
[b]$config['base_url'] = "$this->indexx";[/b]
$config['total_rows'] = $this->db->count_all("application");
$config['per_page']="20";
$this->load->library("pagination");
$this->pagination->initialize($config);

$this->data['register']=$this->applicationmodel->getSelectRegisterOld($kond,$config['per_page']);
$this->data['pagination'] = $this->pagination->create_links();            
$this->load->view('registerold',$this->data);
}

}

headers.php
Code:
<?
echo "<form name=\"form1\" method=\"post\" action=\"$indexx\" enctype=\"multipart/form-data\">";
?>

this view registerold.php

Code:
<?
include "headers.php";
?>
if($fromfilter) {
include "filter.php";
}
else {
if($register->num_rows() > 0) {
echo "<table border=0 cellspacing=1 >";
echo "<tr><td>Nomor Register</td><td>:" . $filter['nomorregister'] . "</td></tr>";
echo "</table>";
[b]echo "$pagination<br>";[/b]
include "reportregister.php";
}
}
&lt;? include "footers.php"; ?&gt;

reportregister.php
Code:
echo "<br><table border=1 align=center cellspacing=0 cellpadding=0>";
foreach ($register->result() as $row) {
echo "<td>$row->nomorregister</a></td>";

.....


}
echo "</table>";

and this model

Code:
function &getSelectRegsiterOld;($konds = '',[b]$config = '0'[/b] )
{
if($failed) {
        $bat = $this->failed;
        $kond = $konds . ' ';
        $ni = " 1 ";
    }
    
    else
     {
        
        $kond = ' AND result = 1' . $konds;
    }
$grant = "SELECT *, replace(substring(substring_index(nomorregister, '.', 4), length(substring_index(nomordaftar,'.',3 - 1)) + 1),'.', '') AS no FROM application WHERE (replace(substring(substring_index(nomorregister, '.', 1), length(substring_index(nomorregister,'.',2 - 1)) + 1),'.', '') = $bat $kond ORDER BY nomorregister DESC LIMIT [b]$config[/b]";
}

........

$result =  $this->db->query($grant);

.........

how & what can i do?


how to create paging with form search, but query string enable?? - El Forum - 12-02-2008

[eluser]hyperfire[/eluser]
My guess would be for you to use this :

http://localhost/application/index.php/application/20

Instead of:

http://localhost/application/index.php?c=application/20

Then use something like this to get your variables from URI:

$c = $this->uri->segment(2); // gets the 20 from application/20

Also, your pagination base_url var should look like this:

$config['base_url'] = base_url() . 'application/';

Hope this help.


how to create paging with form search, but query string enable?? - El Forum - 12-02-2008

[eluser]JoostV[/eluser]
I'm not quite sure what you mean.

If you use the default CI installation it will kill all get variables. If you still wish to use get vaiables, like ?c=application, it's in tghe user guide: http://ellislab.com/codeigniter/user-guide/general/urls.html

I can't explain it better than it is done there, I'm afraid.