How do I view characters in a foreign language (like Bangla) in CakePHP?

Here's my code inside a .ctp file in CakePHP:

<div class="AccordionPanel">
        <div class="AccordionPanelTab">জন্ম নিবন্ধন</div>
        <div class="AccordionPanelContent">
            <?php echo $html->link(__('থানা', true), '/ReportBirthRegistrationStations/'); ?>
            <?php echo $html->link(__('অফিসার', true), '/ReportBirthRegistrationOfficers/'); ?>
         </div>
</div>

      

So, it's pretty clear what I'm trying to do: I'm trying to write Bangla symbols inside my view code in my CakePHP project, and I want to display them in my view page.

When I try to load the browsing page - unreadable characters appear instead of Bangla characters.

I have included this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      

UTF-8 encoding at the top of the file, but still it doesn't work.

I have also included UTF-8 encoding in the view layout files, but I am still running into a problem.

How can I view Bangla or any other foreign characters in CakePHP? Does CakePHP support Bangla?

My IDE is NetBeans 8.0.1.

My CakePHP version is 1.2.5 and PHP version is 5.2 [due to working on a very old project that has been maintained since 2008-09)

Edit - 1:

I tried to add the following -

-J-Dfile.encoding=UTF-8

      

in my file netbeans.conf

in the etc folder of my Netbeans install folder. By doing this, I wanted to make sure my file was saved in UTF-8 encoding. But my problem is still not resolved.

Edit - 2:

I forgot to mention one important point. Whatever I try to display has nothing to do with my database values. These are just shortcuts, I just want to view these tags in Bangla on page load.

+3


source to share


3 answers


Actually the problem was with my default.ctp

file in the folder app/views/layouts

.

The tag was <meta http-equiv>

not UTF-8 encoded, it was ISO-8859-1 encoded. As shown below:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

      

This is the Cake standard - the view file default.ctp

in the folder app/views/layouts

is shared throughout the application and defines the default behavior and common attributes for all view pages.



Since this is a very old project and the HTML version was then HTML 4, the code was written this way. UTF-8 encoding is supported by HTML5. Check the following for more information: http://www.w3schools.com/tags/ref_charactersets.asp

I just had to change this to UTF-8 encoding and then it worked.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      

The problem had nothing to do with the Cake version and the PHP version. Most likely, it was about the HTML version and related code that caused the confusion.

+1


source


Add this code to your ~ / app / config / core.php file:

Configure::write('App.encoding', 'UTF-8');

      



And in the section of your page add:

 <?php echo $html->charset(); ?> 

      

+4


source


Your web server may not have set the correct content type for the request.

You can try to set it manually in your AppController in beforeRender ();

header('Content-Type: text/html; charset=utf-8');

Also note that when you write something to the output stream in the controller before sending the headers to the client, this will also break. (It happens often in debug mode)

+4


source







All Articles