Welcome Guest, Not a member yet? Register   Sign In
how to pass a simple parameter in view to controller ?
#1

[eluser]ludo31[/eluser]
Hello ;

I begin with CI and I would like to know how to pass a simple parameter in view to controller .because sometimes , in view we use form_input and other form and to catch them in controller , we use : input->post
for example in this example I would like to pass a simple value : $identifiant_chaussure to another controller function site/do_upload

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Bienvenue dans l'Image&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <h1>Bienvenue dans l'Image des chaussures </h1>
    
    &lt;?php
    
      
    
        if(isset($identifiant_chaussure))
        {
            echo 'identifiant:'.$identifiant_chaussure ;
        }
        
          
    ?&gt;
    
    
    
    
              &lt;?php echo form_open_multipart('site/do_upload'); ?&gt;
              
              &lt;?php echo form_label('Identifiant', 'chaussure'); ?&gt;<br/>
             &lt;?php echo form_input('identifiant', $identifiant_chaussure); ?&gt;<br/>
        
        
        
                 &lt;input type="file" name="userfile" size="20" /&gt; <br/>
                
                 &lt;?php echo form_button('ajouter','Ajouter'); ?&gt;
        
                    &lt;?php echo form_submit('envoi', 'Envoyer'); ?&gt;
                    
             &lt;?php echo  form_close(); ?&gt;
    
  
    
&lt;/body&gt;
&lt;/html&gt;

and what I make to do that :
I put it in input

Code:
&lt;?php echo form_input('identifiant', $identifiant_chaussure); ?&gt;<br/>

and in controller I catch it like that
Code:
public function do_upload()
             {
                
                  $identifiant_chaussure = $this->input->post('identifiant');

.....}

so for the same problem I would like to pass a n array where there are a lot of information

thanks
#2

[eluser]Mauricio de Abreu Antunes[/eluser]
You have no problems in your code.
What error are you getting?
#3

[eluser]meigwilym[/eluser]
You need something like this in the controller that controls the view:
Code:
$data['identifiant_chaussure'] = 'Mon Chaussure';

$this->load->view('mon_view', $data);
Et voila! The $data array is extracted to give you the $identifiant_chaussure variable.

Mei
#4

[eluser]ludo31[/eluser]
No you don't understand , I d like to pass $identifiant_chaussure to Controller without passing by

Code:
&lt;?php echo form_input('identifiant', $identifiant_chaussure); ?&gt;<br/>
#5

[eluser]CroNiX[/eluser]
Either using a form and submitting it to a controller, or with an anchor and pass the parameter in a segment.
#6

[eluser]ludo31[/eluser]
[quote author="CroNiX" date="1330104637"]Either using a form and submitting it to a controller, or with an anchor and pass the parameter in a segment.[/quote]

And how to catch it in controller ???

Code:
$this->uri->segment(3)


thanks

it doesn't work :

in my controller

Code:
&lt;?php


class Blog extends CI_Controller {

       public function __construct()
       {
            parent::__construct();
          
       }
      
       public function index()
       {
          
           //$this->load->view('blog_view');
           $this->load->view('parametre');
          
       }
      
       public function recevoir()
       {
        $var = $this->uri->segment(3);
        
         echo $var; exit;
       }
}

?&gt;

in my view

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;parametre&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <h1>passage</h1>
    
  
    
    &lt;?php
    
      $variable = 'je suis a passer';
    echo form_open('blog/recevoir');
    
    ?&gt;
    
      &lt;?php
      
       echo form_label('what is your name', 'name');
      
       echo form_input('name', ' ');
      
       echo form_label('what is your Prenom ', 'prenom');
      
       echo form_input('prenom', ' ');
      
       echo form_submit('bouton', 'Envoyer');
      
       [b] echo anchor('controllers/blog', $variable);[/b]
        
      
      
      
      ?&gt;
    
    
    
    &lt;?php echo  form_close(); ?&gt;
    
&lt;/body&gt;
&lt;/html&gt;
#7

[eluser]InsiteFX[/eluser]
Code:
public function recevoir()
{
    $var = $this->input->post('form_value', TRUE);
        
    echo $var; exit;
}
#8

[eluser]ludo31[/eluser]
[quote author="InsiteFX" date="1330125269"]
Code:
public function recevoir()
{
    $var = $this->input->post('form_value', TRUE);
        
    echo $var; exit;
}
[/quote]

it returns false

form_value does not exist even in doc ??
#9

[eluser]InsiteFX[/eluser]
form_value is the name of your form field!
#10

[eluser]ludo31[/eluser]
But here I want just to pass a simple value not a form .$identifiant_chaussure ;

in php it'is possible :

Code:
<a href="bonjour.php?nom=Dupont&amp;prenom=Jean">Dis-moi bonjour !</a>

and we catch them

Code:
&lt;?php
if (isset($_GET['prenom']) AND isset($_GET['nom'])) // On a le nom et le prénom
{
echo 'Bonjour ' . $_GET['prenom'] . ' ' . $_GET['nom'] . ' !';
}
else // Il manque des paramètres, on avertit le visiteur
{
echo 'Il faut renseigner un nom et un prénom !';
}
?&gt;

I try to do that :

&lt;?php

echo anchor('site/envoyer', 'Envoyer','title="news title"');

?&gt;

or

Code:
echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));

but I don(t know how to get the value of title




Theme © iAndrew 2016 - Forum software by © MyBB