Welcome Guest, Not a member yet? Register   Sign In
mixed URL's
#1

[eluser]Unknown[/eluser]
Hi all!
I am searching the right way... =)
How can I use this url, for example,
http://example.com/controller/method/?pa...&par2=val2 ... etc
I like CI scheme /controller/method/arguments_1/arguments_2
But best way (sometimes) is use mixed url...

is it possible with CI help ??

sorry for my ugly English (
#2

[eluser]xwero[/eluser]
You can set the url_protocol to INFO_PATH and set the enable_query_strings to TRUE to use query strings. The problem with this method is that it isn't pagerank friendly because then your pages are reachable with controller/method and ?c=controller&m=method. So you have to find something to make urls that don't need GET unreachable.
#3

[eluser]tomcode[/eluser]
You can use

http://example.com/controller/method/val1/val2/val3

and fetch with
Code:
$segments = $this->uri->segment_array()

See details and more methods in the User Guide
#4

[eluser]Sumon[/eluser]
another way to get url value is:
Code:
class controller_name
{
  function method($var1,$var2,$var3)
  {
    // make sure you have passed 3 parameter correctly
    echo $var1. $var2. $var3;
  }
}
or if you are not sure 3 parameters will set or not then you can assign default value to parameter.
Code:
function method($var1='',$var2='',$var3='')
  {
    if($var3=='')
       //missing url action
    else
       //do action
  }
#5

[eluser]Crafter[/eluser]
xwero, tomcode and Sumon are all spot on.

But understand that your usage
http://example.com/controller/method/?pa...&par2=val2
is incorrect.

The reason for this is that Code Igniter works with "smart urls" by rewriting the index,php file. So you should be using
http://example.com/index.php?c=controlle...&par2=val2

In addition, CI overwrites and hides _GET, so you can't easily reach the URL agruments.

If you want to use flexible options use a scheme like this, or similar,
http://example.com/controller/method/par...,par2=val2
but then you'll have to separate the arguments yourself, and configure CI so that it allows the special characters you use.

Let us know how it goes.
#6

[eluser]Unknown[/eluser]
[quote author="Crafter" date="1221567070"]
If you want to use flexible options use a scheme like this, or similar,
http://example.com/controller/method/par...,par2=val2
but then you'll have to separate the arguments yourself, and configure CI so that it allows the special characters you use.

Let us know how it goes.[/quote]

cool idea! I'll will try!
#7

[eluser]Bramme[/eluser]
what about example.com/controller/method/var1/var2/?path=path/to/file.txt How should you handle that?
#8

[eluser]xwero[/eluser]
The problem with tomecodes solution is that none of the segments are optional, if you want them to be you need to do a lot of checking.

Crafter why are mixed urls incorrect? google uses http://www.google.be/search?q=... . If you translate that to CI search is the controller and the method is index. The query string are the parameters. You don't even have to add a custom route to make this work.

Why should you waste additional code for splitting segments if you can separate the PATH_INFO part from the query strings? This is what adding parameters as segments and your solution does.

If you follow the instructions in my first reply the GET global will not be cleared and you can use it as you where used to in 'plain' php. It's not because CI prefers it one way you should follow it blindly.
#9

[eluser]Bramme[/eluser]
So xwero, for my problem, I should follow your advice as in the first reply?
#10

[eluser]xwero[/eluser]
Bramme i think you are doing something tricky. You shouldn't show your file structure in your url. Can't you get the file path based on the parameter segments in the url?




Theme © iAndrew 2016 - Forum software by © MyBB