Welcome Guest, Not a member yet? Register   Sign In
send blanks with the the pagination (missing parameters)
#1

[eluser]jozeunico[/eluser]
How can i Send a whitespace or "nothing" with the pagination.

I mean

my function it's something like this

Code:
function search($id,$id_cat,$somedata,$offset){
}

and in my $config['base_url']

Code:
$config['base_url'] = base_url()."index.php/usuario/busquedasimple/SimpleDoc/".$id."/".$id_cat."/".$somedata;

But for example If I don't send the field $somedata (its an input text) My query it works just the first time (after submit), and when I click at the pagination links, it doesn't works because the var $somedata doesn't have any value in the url the paramer it's missing, i don't really how to explain better.

base_url()."index.php/usuario/busquedasimple/SimpleDoc/".$id."/".$id_cat."/".MISSING

any idea? to send empty vars by the url like parameters?
#2

[eluser]bcorcoran[/eluser]
Try changing your function to this:

Code:
function search($id,$id_cat,$somedata = '',$offset){
}

I didn't test it (because I'm not clear on what your problem is exactly), but that provides a default blank value to that parameter... so if one is not supplied... it takes that.
#3

[eluser]TheFuzzy0ne[/eluser]
We could really do with seeing your controller. But basically, you can build your base URL progressively, one segment at a time.

Code:
$base_url = base_url() . 'index.php/usuario/busquedasimple/SimpleDoc';

if ( ! empty($id))
{
    $base_url .= "/$id";

    if ( ! empty($id_cat))
    {
        $base_url .= "/$id_cat";

        if ( ! empty($somedata))
        {
            $base_url .= "/$somedata";
        }
    }
}
The above code is untested, but hopefully fits in with what you're trying to do.

Hope this helps.
#4

[eluser]jozeunico[/eluser]
This is my controller (Just the important thing for this)
Code:
function SimpleDoc($id_fondo,$tipo,$productor=0,$personas=0,$anio=0,$inicio=""){
    $this->load->library('auth');
    $this->load->helper('url');        
    $this->load->library('pagination');
    $this->load->model("ImagenesDocumentos");
    $this->load->model('UserModel');    
    $this->load->database();
    $this->load->Model("DocumentModel");        

          

        $total = $this->DocumentModel->totalBusquedaSimpleDos($id_fondo,$tipo,$productor,$personas,$anio,$inicio);    



    $config['base_url'] = base_url()."index.php/usuario/busquedasimple/SimpleDoc/".$id_fondo."/".$tipo."/".$productor."/".$personas."/".$anio;

    $config['num_links'] = 5;
    $config['uri_segment'] = 9;        
    $config['total_rows'] = $total;
    $config['per_page'] = 1;          
    
    $this->pagination->initialize($config);


    $documentos['paging_links'] = $this->pagination->create_links();                

     $this->load->view('user/header_user');

     $datos['user']=$this->auth->getUserName();
     $this->load->view('user/logdata',$datos);
     $this->load->view('user/menu');
     $this->load->view("seccion/busquedaSimpleDoc",$documentos);
     $this->load->view('footer');                      

      

    
    }

I send the vars to function "buscar" with this js
Code:
$("#busquedaSimple").submit(function (){  

                   var data = "tipo="+$("input[@name='tipo']:checked").val()+"&tipologia;="+$('#tipologia').val()+"&productor;="+$('#productor').val()+"&personas;="+$('#personas').val()+"&anio;="+$('#anio').val();
                   //alert(data);
                  
                       $.ajax({
                
                          type:"POST",
                          url:CI_ROOT+"index.php/usuario/busquedasimple/buscar",
                          data: "id_fondo="+$('#id_fondo').val()+"&tipo;="+$("input[@name='tipo']:checked").val()+"&tipologia;="+$('#tipologia').val()+"&productor;="+$('#productor').val()+"&personas;="+$('#personas').val()+"&anio;="+$('#anio').val(),
                          success: function(data){
                            $('body').html(data);
                          }
                        
                    });

The function "buscar" it's just a validation
Code:
function buscar(){

        extract($_POST);
        

        if ($tipo==1)

            $this->SimpleDoc($id_fondo,$tipologia,$productor,$personas,$anio);

    }
#5

[eluser]jozeunico[/eluser]
[quote author="brendanc" date="1236134283"]Try changing your function to this:

Code:
function search($id,$id_cat,$somedata = '',$offset){
}

I didn't test it (because I'm not clear on what your problem is exactly), but that provides a default blank value to that parameter... so if one is not supplied... it takes that.[/quote]

I did't but it doesn't works :down:, even I thought that was the solution, but I don't know why it doesn't works properly.
#6

[eluser]jozeunico[/eluser]
I couldn't fix that problem So What I did it was this:

Get by Id the values from the form (with jQuery), send them with ajax and If some field it doesn't have value assigned a "_" (an sql wildcard) to make it useful for the query and don't lost a parameter at the pagination.
#7

[eluser]TheFuzzy0ne[/eluser]
I still don't fully understand what the problem was to begin with. Please could you show the code you've used to bypass the issue?
#8

[eluser]jozeunico[/eluser]
PART ONE

Ok here it goes the full thing:
This the js
Code:
$(document).ready(function() {
        
            $("#busquedaSimple").submit(function (){  

//I DO THIS TO GET THE ACTUAL VALUES FROM THE FORM AND SEND THEM TO THE CONTROLLER
//SOME FIELDS (anio,tipo,tipologia ARE CREATE THEM WITH AJAX REQUEST
                   var data = "&id;_fondo="+$('#id_fondo').val()+"&tipo;="+$("input[@name='tipo']:checked").val()+"&tipologia;="+$('#tipologia').val()+"&anio;="+$('#anio').val()+"&productor;="+$('#productor').val()+"&personas;="+$('#personas').val();
            
                  
                  
                       $.ajax({
                
                          type:"POST",
                          url:CI_ROOT+"index.php/usuario/busquedasimple/buscar",
                          data: data,
                          success: function(data){
                            $('body').html(data);
                          }
                        
                    });    
                    return false;    
                              
            });

First My View
Code:
<div id="contenido">


<div id="texto">

<table id="busqueda">

// I GET THE FONDO'S LIST FROM CONTROLLER THAT LOAD THIS VIEW
        &lt;?php echo form_open('usuario/busquedasimple/buscar',"id='busquedaSimple'");
            $attributes = array('name' => 'id_fondo',
                                'id' => 'id_fondo',
            );
            
        $value[0]="";        
        foreach($fondos as $fondo){
                $value[$fondo['id_fondo']]=$fondo['familia'];
        }
        echo "<tr><th colspan='3'><h1>Busqueda Simple</h1></th></tr>";
            echo "<tr><td>Fondo:".form_dropdown('id_fondo',$value,0,"id='id_fondo'"). "</td><td id='anios1'>A&ntilde;o </td></tr>";          
    

          echo "<tr id='radioBut'>";        

            

        $attributes = array('name'=>'tipo',                                

                'id'=>'documentos',

                'value'=>1,

                'checked'=>true

            );            


            echo "<td colspan='2'>Buscar en:".form_radio($attributes)."<label for='documentos'>Documentos</label>";

        
        
        

       $attributes = array('name'=>'tipo',

                'value'=>2,

                          'id'=>'fotos'                

            );

    echo "".form_radio($attributes)."<label for='fotos'>Fotos</label>";

            
    $attributes=array('0'=>"Indiferente");


    echo "<tr id='tipo'><td colspan=4>Tipo (obra,documento)".form_dropdown('tipologia',$attributes,0,"id='tipologia'")."(Selecciona donde buscar antes por favor)</td></tr>";

        $attributes=array('name'=>'productor',
                          'id'=>'productor','maxlength'=>'20','size'=>'15');

    
         echo "<tr><td>Productor: ".form_input($attributes)."</td></tr>";
            
    $attributes=array('name'=>'personas',
                          'id'=>'personas',
                          'maxlength'=>'20',
                          'size'=>'15');

         echo "<tr><td>Personas: ".form_input($attributes)."</td></tr>";

    
    echo "<tr><td>&lt;input class='button2' type='submit' name='buscar' value='Buscar'  /&gt;&lt;/td>";            

    echo "</tr>";
echo form_close(); ?&gt;
</table>
</div>
</div>
Finally the controller "buscar" (it's used in the ajax request), how you can see tipo it's just to call other function in this controller (SimpleDoc)
Code:
function buscar(){    
    extract($_POST);
    if ($this->auth->isLoggedIn()){
        $this->load->library('form_validation');
        $this->form_validation->set_rules('productor','Productor', 'trim|required|xss_clean|');
        $this->form_validation->set_rules('personas    ','Peronas', 'trim|required|xss_clean|');
        $this->form_validation->set_message('required', 'Ingrese algun texto para buscar por favor');                          
    
    if (!$this->form_validation->run() == FALSE){
    
            redirect('usuario/busquedasimple');
         }                                                      
         elseif($tipo==1){     //HERE WITH TIPO=1 WE CALL SimpleDoc (THE CONTROLLER TO DO THE QUERY AND PAGINATION  IN FACT WHERE I HAVE THE PROBLEM                      
                $this->SimpleDoc($id_fondo,$tipologia,$productor,$personas,$anio,0);            
                   }elseif($tipo==2){
                $this->do_busquedaSimpleFotos($cadena,0);                
                   }elseif ($tipo==5){
                $this->do_busquedaSimplePostales($cadena,$tipo,0);                        
                   }
              
     }else
             {
                    $this->load->view('header');
                    $this->load->view('login');
                    $this->load->view('guess/aviso');
                    $this->load->view('footer');
            }

        

}
#9

[eluser]jozeunico[/eluser]
PART TWO

And here is the function Simple Doc
Code:
function SimpleDoc($id_fondo,$tipo,$productor= '',$personas = '',$anio = '',$inicio=0){
    

           $this->load->library('auth');

    $this->load->helper('url');        

        $this->load->library('pagination');

    $this->load->model("ImagenesDocumentos");

        $this->load->model('UserModel');    

    $this->load->database();

    $this->load->Model("DocumentModel");

    
        $total = $this->DocumentModel->totalBusquedaSimpleDos($id_fondo,$tipo,$productor,$personas,$anio,$inicio);    
        $this->output->enable_profiler(TRUE);

if ($total>0){ //IF WE GET AT LEAST ONE REGISTER
        $config['base_url'] = base_url()."index.php/usuario/busquedasimple/SimpleDoc/".$id_fondo."/".$tipo."/".$productor."/".$personas."/".$anio;

        $config['num_links'] = 5;

        $config['uri_segment'] = 9;        

        $config['total_rows'] = $total;

        $config['per_page'] = 1;

        $documentos = array('documento'=>$this->DocumentModel->busquedaSimpleDos($id_fondo,$tipo,$productor,$personas,$anio,$inicio));    

            $documentos['imagenes'] = $this->ImagenesDocumentos->getImagesToShowTheUser($documentos['documento'][0]['id']);




        $this->pagination->initialize($config);



        $documentos['paging_links'] = $this->pagination->create_links();        

                        $this->load->view('user/header_user');

                        $datos['user']=$this->auth->getUserName();

                        $this->load->view('user/logdata',$datos);

                        $this->load->view('user/menu');

                        $this->load->view("seccion/busquedaSimpleDoc",$documentos);

                        $this->load->view('footer');

            

            

       }//is logged in (it means if you are not logged and try to acccess this controller
                else{

                        $this->load->view('header');

                        $this->load->view('login');

                        $this->load->view('guess/aviso');

                        $this->load->view('footer');

                    }                                
    }
}

I tried to let it "light", well here it goes my problem
1.- If I send from the form ALL THE FIELDS, the controller SimpleDoc it Works properly
2.- But when I don't send one field (let's supose that I didn't populate the field "productor" the controller just it works properly the firs time (When show the view with results and pagination)

BUT If I check the pagination links it's missing one parameter (the one that I didn't populate)and then the function SimpleDoc doesn't work properlu because the parameters that receive it doesn't match with the parameters that sends the pagination links.In fact the controller works, but the parameters in the model neither match and the query doesn't return the result that I hope.

Well, I do my best to explain and post almost all my code, thanks for your time.
Ah,Even the validation in buscar doesn't work thats the reason because I decide to set the fields that the user don't populate in the form (my replay 2 post before,with jquery).

p.d. almost forget it , thanks for your time




Theme © iAndrew 2016 - Forum software by © MyBB