• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to inspect the data array in the view.

#1
[eluser]scaryjack[/eluser]
hi,
is there any way to see ALL data an item contains in the view?

to make it more clear:
in the controller I load the view and give in the second parameter an data array.

So how can I inspect the data array( e.g. that it shows all identifiers)? In CakePHP you could easliy print everything with one function call.

#2
[eluser]Michael Wales[/eluser]
Code:
var_dump($data); // Or whatever your array is named

#3
[eluser]elvix[/eluser]
I always create a helper function that takes an array and prints it out surrounded by pre tags for easier reading. You could use var_dump() in there as well.

in custom_helper.php:

Code:
function print_rr($arr) {
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}

#4
[eluser]scaryjack[/eluser]
the helper is a good idea.

but one thing remains unclear...
if I have this:
this->load->view("view", $data);

how can I print $data in the view? Because I access the values in the view directly, never call the $data var.
Or is this possible and I missed all the time to try it?

#5
[eluser]myerman[/eluser]
do a var_dump() or print_r() from your controller function....that will dump it out onto your view....

#6
[eluser]scaryjack[/eluser]
ok, thx alot!

#7
[eluser]Colin Williams[/eluser]
Better solution if there is HTML code in your $data array:

Code:
function print_rr($arr, $store = FALSE)
{
   $output = '<pre>'. htmlspecialchars(print_r($arr, TRUE)) .'</pre>';
   if ($store === TRUE)
   {
      return $output;
   }
   else
   {
      print $output;
   }
}

#8
[eluser]Bramme[/eluser]
You could use the xmp tag instead off pre, so you wouldn't have to use the htmlspecialchars function, but on the other hand, it's deprecated... So we shouldn't be using it at all...

#9
[eluser]khmer angkor[/eluser]
Code:
function updateProfile($userID) {
        $data = array(
                    'password' => $this->password,
                    'fullname' => $this->fullname,
                    'phone' => $this->phone,
                    'email' => $this->email
                    );
        $this->db->where('userID', $userID);
        $status = $this->db->update('sys_user', $data);

        return $status;

#10
[eluser]Bramme[/eluser]
[quote author="khmer angkor" date="1217421645"]
Code:
function updateProfile($userID) {
        $data = array(
                    'password' => $this->password,
                    'fullname' => $this->fullname,
                    'phone' => $this->phone,
                    'email' => $this->email
                    );
        $this->db->where('userID', $userID);
        $status = $this->db->update('sys_user', $data);

        return $status;
[/quote]
And that has what to do with this topic?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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