CodeIgniter: Passing Arguments from View to Controller? CodeIgniter: Passing Arguments from View to Controller? codeigniter codeigniter

CodeIgniter: Passing Arguments from View to Controller?


You should do that in your Controller before you are passing the data to the View.Try with something like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');class Welcome extends CI_Controller {    public function index()    {        // Load Model        $this->load->model('Bookmarks');        // Get Latest Bookmarks        $query = $this->Bookmarks->get_latest_bookmarks(4);        $bookmarks = array();        $tags = array();        foreach ($query->result() as $row) {             $bookmark_query = $this->Bookmarks->get_bookmark_tags($row->id);             $bookmark_arr = array();             foreach (bookmark_query->result() as $bookm) {                 array_push($bookmark_arr, $bookm);             }             array_push($tags, $bookmark_arr);             array_push($bookmarks, $row);        }        $data['tags'] = $tags;        $data['bookmarks'] = $bookmarks;        // Load and Pass Data into View        $this->load->view('welcome_message', $data);    }} 


You don't.

The point in using a Framework is to default to proper standards. CodeIgniter follows a loose MVC pattern but you should never pass things from the view to the controller.

You can do it, but if you do it you'll be getting into a spaghetti mess pretty soon.

Grab the ID's on the controller. Even if it implicates running the same loop twice. You'll thank yourself latter on.