Framework: CodeIgniter 2.0
I am trying access session data setup in model from view.
This is the code I am testing in view:
<script type='text/javascript'>
function notEmpty(elem, helperMsg){
var num_records = '$this->session->userdata("number_Of_Records_session")';
alert(num_records);
if(elem.value.length > 0){
alert(helperMsg);
elem.focus();
return false;
}else{
window.location="/path/";
}
return true;
}
</script>
When I use PHP code I could retrieve the value from session and display it.
<?php
$numberOfRecords_session =
$this->session->userdata('number_Of_Records_session');
echo "Num records:".$numberOfRecords_session;
?>
But in javascript this line
var num_records = '$this->session->userdata("number_Of_Records_session")';
print this message in alert box:
$this->session->userdata("number_Of_Records_session")
Any advice to retrieve value in javascript and show it alert box is appreciate.