I am trying to pass a variable from a controller to a view. I have some code but in order to understand what is the problem I made it simple. Here is my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
$p=2;
public function index()
{
$this->load->view('welcome_message',$p);
}
}
?>
Variable p is declared in the view.
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<?php echo $p?>
</div>
When I try to display the $p value, I obtained the error:
ERROR
Parse error: syntax error, unexpected '$p' (T_VARIABLE), expecting function (T_FUNCTION) in C:\wamp\www\..\application\controllers\welcome.php on line 20
What's wrong?
Thanks.