skip to Main Content

I am trying to display a value $raw which is in an array format to a textbox in a CodeIgniter view

This is the function I am using in my controller:

public function pricing($raw='array')
{
    if ($raw === 'array')
    {
        return $this->result_array();
    }
}

I tried this but still getting message:array to string conversion

I am using $raw in my view ‘add_calendar.php’:`

<?php echo(['name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=>'$raw'])?>

2

Answers


  1. Pass the array from the controller to view

    $raw is a variable don’t use single quotes ' for it

    $data['record'] = array('name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=> $raw);
    return $this->load->view('file', $data);
    

    View

    You can use these values with or without HTML tags

    Without HTML tags

    <?= $name ?> //tohar
    <?=  $class ?> //form-control
    <?= $raw ?>
    

    With HTML tags

    <td><?= $name ?></td>
    <p><?= $name ?></p>
    <h3><?= $name ?></h3>
    
    Login or Signup to reply.
  2. You can not echo an array because echo expects string as its parameter. Since you are trying to echo the values to a textbox you may want to do this.

    When you load your view pass $raw to your view.

    $data = array('raw'=>$raw);
    $this->load->view('add_calendar', $data);
    

    Then in your view use form_input to create a textbox.

    echo form_input(['name'=>'tohr','class'=>'form-control','placeholder'=>'Enter total hire rate','value'=>$raw]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search