Welcome Guest, Not a member yet? Register   Sign In
Passing multiple uri / url parameters with CI
#1

[eluser]Wittner[/eluser]
Hi,

I'm building as part of an application, a booking engine. A diary view is presented to the user with hyperlinks on each date. If they wish to make a booking they click on the date's link and a dhtml pop-up window appears with some of the data pre-loaded (that's the theory anyhow!). I'm a newbie to mvc, OOP and CodeIgniter. In my old procedural days (last month!) I would have passed an id code and date for instance to the new window using this kind of structure in the link:

Code:
<a >4/08/2008</a>

Codeigniter handles things differently, using segments. My question is, how do I pass these two (or more) variables to a new window using CodeIgniter best practice? Do I need to use a form instead of a link? Can CI handle multiple segments such as:
Code:
<a >4/08/2008</a>

I'm just looking for guidance for 'best practice' not necessarily code. A pointer in the right direction would be great!

(code samples above simplified for clarity)

cheers,

Wittner

p.s. I should mention that I'm in love with CodeIgniter. Don't know what I did without it before ;-)
#2

[eluser]Seppo[/eluser]
I believe you had js code and the forum stripped it so... try putting it again, and add some spaces between on and click, for example "on click"
#3

[eluser]Dagobert Renouf[/eluser]
Hey Wittner.

As a proud experienced member of the community (yeah I'm a user for 2 weeks, rock-hard advices right ?), I'll tell you how I see this thing :

As you saw in the userguide, struture of ci url's is like that : example.com/class/function/parameter1/param..

I don't see a problem in structuring things that way :

yoursite.com/book_engine/diary/04/08/2008

or that way : yoursite.com/book_engine/diary/04-08-2008 (in case you want just one variable, you just explode it afterwards).


I think a master thought could help you confirm or not what I said here, but for now I'm all you've got.
#4

[eluser]Wittner[/eluser]
Code:
<a >Link text</a>

erm... the code only had a simple href. I took out JS to save on complication. Looked fine in the preview, that's odd Seppo, there was no JS, just a simple href. Anyhoo, I suppose it doesn't really need a code sample, what Im trying to do is pass in more than one parameter. So:

blah.php/model/function/variable1

I can understand. But can I do:

blah.php/class/function/variable1/variable2/variable3 etc......?

Is that the way CI likes to see it?

Dagobert
"but for now I’m all you’ve got"

Hehe, I'll take any help I can get mate!

;-)

cheers,

Wittner
#5

[eluser]Wittner[/eluser]
that href didn't work again!

:-(

Wittner
#6

[eluser]charlie spider[/eluser]
Wittner and Dagobert Renouf,

welcome to CI


Wittner,

yes you can pass as many variables as you like as long as the first url segment is the class name (controller) and the second is a function within that controller.

i wouldn't use a form for what you are talking about.
#7

[eluser]Wittner[/eluser]
Thanks Charlie. Do I separate them with slashes as in my example?

cheers,

Wittner
#8

[eluser]charlie spider[/eluser]
yes sir


your url's should look similiar to what Dagobert Renouf wrote:


yoursite.com/book_engine/diary/04/08/2008

or:

yoursite.com/book_engine/diary/04-08-2008 (in case you want just one variable, you just explode it afterwards)
#9

[eluser]Wittner[/eluser]
Thanks Charlie. I get it now. I'm off to explore this and drop a note as to how it worked. Thanks to all you guys for the help.

(p.s. Had a look at Pyfo, v. nice site and some really good work. My wife and I are a designer/programmer combo too - ever notice how *designers* get all the compliments!!!!)

;-)

cheers,

Wittner
#10

[eluser]Wittner[/eluser]
That worked a treat:

I set a variable in the model equal to the controller function that shows the pop-up window, like this:

Code:
$bookingWindow/$propertyId
(this appears in the JS script for the pop up link as my target page)

Then used:

Code:
$data['propertyId'] = $this->uri->segment(3, 0);
in the controller, and passed the array off to the resulting page load function. This worked a treat and the Id was echoed properly on the final page. Time for a celebratory coffee! Once again, many thanks for the help.

cheers,

Wittner




Theme © iAndrew 2016 - Forum software by © MyBB