Welcome Guest, Not a member yet? Register   Sign In
weird characters in the url
#11

[eluser]shadow player[/eluser]
Quote:i add spaces because without them it will echo the greek word in the post

And exactly because of those whitespaces the function hexToStr won't work correctly. Remove them before passing them to the function and it will work.
#12

[eluser]osci[/eluser]
My example is not using a url like
Code:
http://test.loc/welcome/index/search_by_name=Doe+John
but as
Code:
http://test.loc/welcome/index/Doe

i guess this has to do with
Code:
$config['uri_protocol'] = "AUTO";
any info welcome here

The controller (News as seen in site_url below)
Code:
function index($q='-', $offset = 0)
{
   $maxrec = 10;
   $this->load->model('news_model');
   $this->load->library('pagination');

   $config['base_url'] = site_url("news/index/$q");
   $config['total_rows'] = $this->news_model->count_news_q($q);
   $config['uri_segment'] = 4;
   $config['per_page'] = $maxrec;
   $config['num_links'] = 5;

   $render['records'] = $this->news_model->get_pager_records($maxrec,$offset,$q);
   $render['norecords'] = 'No records';
   $this->load->view('page', $render);
}

The model
Code:
function get_pager_records_q($max,$start,$q)
{
   if ($q !=='-'){
      $query = $this->db->from('t_news')->like('title',$q)->limit($max,$start)->get();
   } else {
      $query = $this->db->from('t_news')->limit($max,$start)->get();
   }

   if ($query->num_rows > 0)
   {
      return $query->result();
   } else {
      return false;
   }
}

function count_news_q($q) {
   if ($q!=='-'){
      return $this->db->from('t_news')->like('title',$q)->get()->num_rows();
   } else {
      return $this->db->get('t_news')->num_rows();
   }
}

The view
Code:
&lt;?php if (isset($records) & ($records <> NULL)) { ?&gt;

<table>
<thead><tr><th>Title</th></tr></thead>
<tbody>
&lt;?php foreach($records as $row) : ?&gt;
   <tr><td>
   &lt;?php echo $row->title; ?&gt;
   </td></tr>
&lt;?php endforeach; ?&gt;
</tbody>
</table>
&lt;?php
      echo $this->pagination->create_links();
  } else {
     echo $norecords;
  }
?&gt;

I have to use $q='-' as letting $q='' would produce url with double slashes in this code.
#13

[eluser]dianikol85[/eluser]
[quote author="shadow player" date="1302467151"]
Quote:i add spaces because without them it will echo the greek word in the post

And exactly because of those whitespaces the function hexToStr won't work correctly. Remove them before passing them to the function and it will work.[/quote]


i add them just in here in this post because without them it with prin the greek word. in the script i wrote it without the spaces.


Another weird thing.

i store the search form post in a session and then i pass it to the model and it worked. But the sql query is exactly the same as before. It's getting really fraustrating Sad


I am not comfortable to extend a library yet.
#14

[eluser]dianikol85[/eluser]
osci i follow this technique because i didn't wont to fave so many segments in the url. Maybe i have 5 or 6 keywords at the same time. I tried to do that more dynamically Smile
#15

[eluser]osci[/eluser]
$q could be a serialized array containing your list of and likes ie
Code:
http://test.loc/welcome/index/one+two+three

and in your controller you could convert that to an array
Code:
$q_array = explode('+',$q);

and use that array in your model to loop and create a set of likes
You could extend it to be more dynamic with another segment containing fields.

Code:
http://test.loc/welcome/index/one+two+three/title+content


ie use another array for the fields too.
Code:
$f_array = explode('+',$f);

and combine arrays in model to give you more power


It's up to your requirements Smile
#16

[eluser]InsiteFX[/eluser]
CodeIgniter User Guide - Text Helper

convert_accented_characters()

Transliterates high ASCII characters to low ASCII equivalents, useful when non-English characters need to be used where only standard ASCII characters are safely used, for instance, in URLs.
Code:
$string = convert_accented_characters($string);
This function uses a companion config file application/config/foreign_chars.php to define the to and from array for transliteration.

InsiteFX
#17

[eluser]osci[/eluser]
Wouldn't that mean I would have to make equivalents for each of my greek character to an english equivalent?
meaning ie i for ι or ί and a for α?
that would be something we call in Greece as greeklish (ie γράφω σε ελληνικά = grafw se ellinika,) and it wouldn't be seo friendly, as grafw means nothing to search engines while γράφω does.
#18

[eluser]dianikol85[/eluser]
yes definitely not greeklish. its like trush. only in Greece that lang is understandable and seo doesn't recognize it
#19

[eluser]osci[/eluser]
@dianikol85
the arrays way in comment #14 weren't good for your dynamic requirement?
#20

[eluser]dianikol85[/eluser]
[quote author="osci" date="1302470779"]@dianikol85
the arrays way in comment #14 weren't good for your dynamic requirement?[/quote]

sure it works fine but the problem isn't how to generate the url. The prob is when i have greeks in it. In you example in comment #11 you didn't explain how did you pass the search form variables in the url.

Do you do something like i do? I send the post int a method and in that method i generate the segments and then i redirect with the generating string like that

Code:
redirect('index/'.$generated_string);

I can't think another way on how to pass it to the view in order to have the pagination.


I also want to mention that when i have greeks in the url try to copy the url and paste it in a text document. It prints a hex value of those greek words.

And that hex value pass in the model.

Even if use a func hex to string the sql query still doesn't work. The only way i make it works is that in the method i produce the $generated_string at the same time i store the values in a session and i use that session in the model to achieve a success sql query

It works but with that way i can't share the link because i use a session in the model...


Sad




Theme © iAndrew 2016 - Forum software by © MyBB