Issue
As mention in the title I am trying to send the Session variables in the View Section after I login,
The Session contains let's say name
and email
.
So what I have tried in the Profile Controller Section is below:
class ProfileController extends Controller{
public function index()
{
$session = session();
$userDetails = ['name' => $session->get('name'),
'email' => $session->get('email')];
print_r($userDetails);
echo view('profile', $userDetails);
}
}
although I am able to print the $userDetails
value in the controller Section, the same I am trying in VIEW
is giving me nothing.
here's my profile.php
code in view.
<h3>Welcome to the Profile Section : <?php echo $userDetails['name']; ?></h3>
<p>Your email id : <?php echo $userDetails['email'] ; ?></p>
The output I am getting is :
Please correct me if I am missing something as I am new to the PHP frameworks.
Solution
In your View you would just have the array named indexes as they are converted to variables.
So $userDetails['name']
becomes $name
and
$userDetails['email']
becomes $email
So in your case. Instead of
<h3>Welcome to the Profile Section : <?php echo $userDetails['name']; ?></h3>
<p>Your email id : <?php echo $userDetails['email'] ; ?></p>
You would have.
<h3>Welcome to the Profile Section : <?php echo $name; ?></h3>
<p>Your email id : <?php echo $email ; ?></p>
And you can replace <?php echo
with the shorter version <?=
<h3>Welcome to the Profile Section : <?= $name; ?></h3>
<p>Your email id : <?= $email ; ?></p>
I would strongly suggest to read the CodeIgniter Userguide as it covers this and everything else the framework does. So it's good to get familiar with it.
Answered By - TimBrownlaw
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.