Welcome Guest, Not a member yet? Register   Sign In
Handling url's
#1

[eluser]jacobson[/eluser]
Hello I have a problem. I want to create a controller which will load the apropriate view (take from tha database) of the site like localhost/index.php/games/value1-value2 (the values from the database depends of the value1 and value2)

I want this "value1-value2" with the "-" between them.
Do i have to create controller games with the index function which will take uri segment of this value1-value2. then explode it by "-" after that i'll get 2 variables and value1, value2 assigned to them. And at the end send those values to the model and take the informations from the database. Will it work properly? mabe there is some other way - the better one, more efficient.

Thanks for replying
#2

[eluser]Nick_MyShuitings[/eluser]
better way is games/value1/value2 that would be native CI... the other is as you said, get them both in one param and explode them
#3

[eluser]toopay[/eluser]
serialized array!
Code:
some_table
=======
value_id
serialized_array_values
So you have the url like :
localhost/index.php/games/value_id
#4

[eluser]jacobson[/eluser]
what will be the difference in using this serialized array and juz passing another argument value1-value2 which will be exploded?

I have another problem... I created basic controller

Code:
class mycontroller extends CI_Controller {
    function __construct(){
        parent::__construct();
        echo $this->uri->segment(2);
    }
}

I try to go localhost/mycontroller/value1-value2

After that i get 404 error (because there's method value1-value2) but under the error i get the "value1-value2". What can I do to make this request without error.
#5

[eluser]toopay[/eluser]
Unless you have set an apropriate routes, then your url must be something like
Code:
http://yourdomain.com/somecontroller/somefunction/value1-value2
// Invalid url
http://yourdomain.com/mycontroller/value1-value2
http://yourdomain.com/games/value1/value2

Serialized array is the most efficient way to store the array values in your database!
#6

[eluser]jacobson[/eluser]
mhm Tongue okey.. I've tried routes
$route['val/(:any)'] = 'val';

which means when you pass any variable like val/asnnuobn-cnaoca remap this to the val controller


technically it should work but when I try localhost/index.php/val/ncaojsnc-acnjc, it doesn't change, it also shows me the ncaojsnc-acnjc and after that the 404 error...

Ok, I managed to do it

I make a route
$route['val/(:any)'] = 'val/index/$1';
and in the controller i have function index($val) and it works correctly. Thanks for help
#7

[eluser]toopay[/eluser]
Try this

Route :
Code:
$route['val/(:any)'] = "val/index/$1";

Controller :
Code:
class Val extends CI_Controller {
   function __construct()
   {
       parent::__construct();
       if($this->uri->segment(2))
       {
          echo $this->uri->segment(2);
       }
       else
       {
          redirect('main');
       }
   }
  
   function index($somevalue)
   {
       echo $somevalue;
       //$this->load->view('includes/template');
   }
}
#8

[eluser]jacobson[/eluser]
Ok, thank you very much for your help Smile
It works correctly
#9

[eluser]InsiteFX[/eluser]
HUMMMM! NO CODE!!!!!




Theme © iAndrew 2016 - Forum software by © MyBB