Welcome Guest, Not a member yet? Register   Sign In
passing data from view to controller function?
#1

[eluser]Bhavani Shekhawat[/eluser]
view
Code:
<h1> Your Artifacts </h1>

&lt;link rel="stylesheet" type="text/css" href="css/button.css" title="Default"&gt;

&lt;?php foreach ($rows as $r): ?&gt;
                
&lt;?php echo anchor('site/click_artifact', $r->ArtifactID); ?&gt; |
&lt;?php echo $r->Description; ?&gt; |
&lt;?php echo $r->EnteredDate; ?&gt; |
<p class = "result"> &lt;?php echo anchor('site/delete_artifact'.$r->ArtifactID, "Delete Artifact"); ?&gt; </p>
<p class = "result"> &lt;?php echo anchor('site/modify_artifact'.$r->ArtifactID, "Modify Artifact"); ?&gt; </p>

      
&lt;?php echo "</br>"; ?&gt;

&lt;?php endforeach; ?&gt;

controller
Code:
function click_artifact($link){
              
              $this->members_area();
              $getLink = $link;
              $this->load->model('artifact_model');
              $data['rows'] = $this->artifact_model->display_artifact($getLink);
              $this->load->view('view_artifact', $data);
          }

I basically need the artifactID back from the view. what I want is that when a user clicks on the artifact id link it should get him the details related to that artifact id stored in the db.
#2

[eluser]joeizang[/eluser]
hey,

I think you are looking at capturing variables in ur url's back as variables. I would use the input class to capture this I think so maybe you should be simulating a post request with a user click using javascript. Hope this makes some sense.
#3

[eluser]pickupman[/eluser]
Missing a trailing slash
Code:
&lt;?php echo anchor('site/click_artifact/', $r->ArtifactID, $r->ArtifactID); ?&gt;

To get the id you can use
Code:
function click_artifact($link = FALSE){
              
    if($link == FALSE)
       redirect('site'); //Nothing to lookup

    $this->members_area();
    $getLink = $link; // No reason to set this twice this line can be removed
    $this->load->model('artifact_model');
    $data['rows'] = $this->artifact_model->display_artifact($link);
    $this->load->view('view_artifact', $data);
}

// OR //
function click_artifact(){
    
    $link = $this->uri->segment(3,FALSE);    
    if($link == FALSE)
       redirect('site'); //Nothing to lookup

    $this->members_area();
    $getLink = $link; // No reason to set this twice this line can be removed
    $this->load->model('artifact_model');
    $data['rows'] = $this->artifact_model->display_artifact($link);
    $this->load->view('view_artifact', $data);
}
#4

[eluser]pickupman[/eluser]
Just to add on to the javascript idea, is to always use the same syntax and add js later. Yes, 98% people have it but you never know.
Code:
//Change link to
&lt;?php echo anchor('site/click_artifact/', $r->ArtifactID,$r->ArtifactID, array('title'=> $r->ArtifactID, 'class' => 'artifact_link')); ?&gt;

//jQuery
$("a.artifact_link").click(function(){
  event.preventDefault();
  var id = $(this).attr("title");
  $.load('&lt;?php echo site_url('site/click_artifact');?&gt;' + '/' + id #message); //Fetch url and add to div#message
});
#5

[eluser]Bhavani Shekhawat[/eluser]
I tried the non js solution but it didnt work. However, you solved my other problem that was going on with jquery lol.
#6

[eluser]pickupman[/eluser]
[quote author="Bhavani Shekhawat" date="1279081546"]I tried the non js solution but it didnt work. However, you solved my other problem that was going on with jquery lol.[/quote]

Well, that's a start...what does didn't work mean? I'll try and help, but you'll have to describe the problem.
#7

[eluser]Bhavani Shekhawat[/eluser]
Imagine a database with 3 tables (id, name, phone). What I am doing is anchoring the ID through view. Now I want when I click on a particular ID, it should show me the values associated to it. SQL is not a problem but I need to grab the ID of the link that user clicked to view it. Similarly, ArtifactID is the one I am anchoring and I want that on clicking the ID it should give me necessary info from the database.

Therefore, I am trying to grab to sql id to each link in the view and send it to controller and then the model where it will take the id and perform the query.

Hope that makes it clear.
#8

[eluser]pickupman[/eluser]
Try checking your result from your model. You can add
Code:
echo $link; //Add above your model to see if id is being passed

//or at top of controller in class constructor add
function Site(){
  parent::Controller();
  $this->output->enable_profiler(TRUE); //Output $_request array and DB queries at bottom of page
}

//or
$data['rows'] = $this->artifact_model->display_artifact($link);
var_dump($data['rows']); //Check your result being returned

That should give you some code to figure out where data is lost.
#9

[eluser]crwtrue[/eluser]
If i understanded correctly you could do somethink like this in your controller:

Code:
function click_artifact($link){
              
    $this->members_area();
    $getLink = $link;
    $this->load->model('artifact_model');
    $data['rows'] = $this->artifact_model->display_artifact($getLink);
  
    $row_number = count($data['rows']);
  
    for ($i=0; $i<$row_number; $i++)
    {
    $links = anchor('site/click_artifact/'.$data['rows'][$i]['ArtifactID'],$data['rows'][$i]['ArtifactID']);
    $data['rows'][$i]['ArtifactID'] = $links;
    }
  
    $this->load->view('view_artifact', $data);
}
#10

[eluser]crwtrue[/eluser]
Forget that previous post that was more making that first view well anyways if you pass the ArtifactId on your url you can read that ArtifactId value from click function like this:

$artifact_id = $this->uri->segment(3, 0);




Theme © iAndrew 2016 - Forum software by © MyBB