[eluser]edjon2000[/eluser]
Hello all,
Sorry to pick your brains yet again
1. HTML Entities:
What is the best way to deal with HTML entities, I am currently designing all my views using the XHTML Strict doctype as follows:
Code:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
as well as
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
This is in my header file, consequently, I have the entities issues to deal with.
First of all I have tried adding htmlspecialchars to my form validation rules which works great, up to a point, however if I then update an existing entry, I run into the double encoding problem, e.g.
Code:
Finance & Accounting
and then on update
Code:
Finance && Accounting
Ok, this is a bit annoying to say the least, so perhaps I should not use htmlspecialchars in the validation rules, I have since enabled global xss filtering and removed all my |htmlspecialchars|xss_clean| options from my validation rules, unfortunately the problem still exists but not as badly, now I don't actually get double encoding but I still have to view this in my edit
whatever page.
I tried using htmlspecialchars_decode(PHP 5.x.x) and that removes the appearance of
from the view but, of course kicks up a validation warning.
At the moment, in my database I have data stored with HTML entities, so, should I store the records without encoding? and perhaps encode them on import to the view, and then decode them on update.
Any advice on this would be greatly appreciated as I am sure you have come across this in the past (I did a search prior to posting this but found nothing directly relevant) and what partly related solutions I did find seemed to produce more errors, which brings me to my second question.
2. Undefined Variables
Now this is a weird one, I have found a lot of interesting stuff on these forums but nothing that actually answered my question, which is:-
If I am passing a variable from my controller to my associated view how can I do that in such a way as to prevent an undefined variable problem.
To display my views I use a sort of pseudo_template idea as follows:-
I have a common header and footer and a typical load from my controller is like this
Code:
<?php
/**
* Description of home
*
* @author Jon
*/
class Home extends Controller {
function __construct()
{
parent::Controller();
}
function index()
{
$data = array();
$data['page_title'] = 'Home';
$data['extra_head_content'] = '[removed][removed]';
$data['featured'] = 'site_views/featured_area_view';
$data['main_content_1'] = 'site_views/home_view';
$data['main_content_2'] = 'site_views/forms_view';
$data['vac_name'] = $this->vacancy_model->generate_vacancy_list();
$data['sec_name'] = $this->vacancy_model->generate_sector_list();
$data['vacancies'] = $this->vacancy_model->get_vacancies(array('vacancy_featured' => 'Yes', 'vacancy_active' =>'Yes' ));
$this->load->view('includes/template', $data);
}
}
/* End of file home.php */
/* Location: ./application/controllers/site/home.php */
Now that all seems fine, but when it comes to building the view I get loads of undefined variable warnings in my IDE and I am one of those people that prefers to sort out the problem rather than cover it up, so any PHP notice error I have to correct.
To use the above example, here is the associated view, I will have to post this in my next post