• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling one method from another within the same controller

[eluser]Pedro Luz[/eluser]
Im currently working on a project, and since i dont like the flashdata.. because.. it usualy doesnt work the way i wanted, and i needed to pass messages to the user.. (success, fail, etc), what i did has... in all the methods in the controller i have something like this... i add a $params = array()

class User extends CI_Controller
* Controller default welcome msg
* @var array
private $_cMsg;

function __construct()
$this->_cMsg = array(
    array("type" => "info", "text" => "Welcome to the Users.")

function edit($params = array())
$this->_cMsg = array(
array("type" => "info", "text" => "Edit Users.")

// put together all the incoming messages
$data["msg"] = isset($params["msg"]) ? array_merge($this->_cMsg, $params["msg"]) : $this->_cMsg;

// then you load the views and pass
$this->load->view('something.php', $data);

then what i have in a little view that loads on top of the page
is something like this

$count = 0;
echo "<table class='msg-list'>";
    foreach($msg as $m)
        $msgBox  = "<tr class='msg ".$m['type']."'>";
        $msgBox .= "<td class='icn'></td>";
        $msgBox .= "<td class='msg-text'>".$m['text']."</td>";
        $msgBox .= "<td id='".$count."' class='msg-close'></td>";
        $msgBox .= "</tr>";
        echo $msgBox;
    echo "</table>";

and with this you generate a table with multiple rows.. each with a message

if you want to pass a message to that method, i do somehting like
array_push($msgBag["msg"], array("text" => "Added width success", "type" => "success"));
array_push($msgBag["msg"], array("text" => "Still need to change the users permissions", "type" => "info"));

where im passing 2 messages to the edit method

is not the most accurate way, or the most guru way... but it works for me.

Messages In This Thread
Calling one method from another within the same controller - by El Forum - 02-11-2011, 05:45 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.