views:

109

answers:

3

Hello,

My controls receives some params from the user, I would like to place them inside the view I'm calling, how should I do this without splitting the view into multiple parts?

Thank you.

+2  A: 

If I understand correctly, you should be able to do something like this for your controller

<?php
class Blog extends Controller 
{

  function index()
  {
   $data['title'] = "My Real Title";
   $data['heading'] = "My Real Heading";

   $this->load->view('blogview', $data);
  }
}
?>

And something like this for your view:

<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>

</body>
</html>

This is from the Codeignitor User guide here

Eric LaForce
+1  A: 

In Controller:

function show_something() {

    $data = array();

    if ($this->input->post('some_form_field') {
        $data['form_value'] = $this->input->post('some_form_field');
    }

    $this->load->view('some_view');

}

In View:

<html>
<head>
</head>
<body>

    <?php if ($form_value): ?>
        <h1><?= $form_value; ?></h1>
    <?php endif; ?>

    <form method="post" action="">

        <input type="text" name="some_form_field" />
        <input type="submit" value="Show Value on Page" />

    </form>

</body>
</html>
Zack
+1  A: 

in controller

function show_something() {

    $data = array();

    if ($this->input->post('some_form_field') {
        $data['form_value'] = $this->input->post('some_form_field');
    }

    $this->load->view('some_view', $data);

}

in view

<html>
<head>
</head>
<body>

    <?php if ($form_value): ?>
        <h1><? echo $form_value; ?></h1>
    <?php endif; ?>

    <form method="post" action="">

        <input type="text" name="some_form_field" />
        <input type="submit" value="Show Value on Page" />

    </form>

</body>
</html>
sonill