Welcome Guest, Not a member yet? Register   Sign In
Form a long url
#1

[eluser]katama[/eluser]
Hello.
I have one Admin controller and one Class and one Public controller and one Class.
So there is admin.php Controller. It contains Class Admin.
This class contains functions index, catalog, more .

How can I form such url http://code_int.loc/admin/catalog/more/2 and for example, longer.. instead of current http://code_int.loc/admin/more/2 ?
Thanks.
#2

[eluser]James McMurray[/eluser]
I don't think I understand the question, but I'll try. Smile

You can write the urls however you want them. If you use http://code_int.loc/admin/more/2, the admin controller's more function will be invoked with the first parameter set to 2. If you use http://code_int.loc/admin/catalog/more/2 the admin controller's catalog function will be invoked with the first parameter set to 'more' and the second one to 2.
#3

[eluser]katama[/eluser]
Thank you for reply, and about what parameter do you say..? :long:
#4

[eluser]James McMurray[/eluser]
Unless you change the default installation, codeigniter takes the first section of the url as the controller, the second as the function to call, and the remaining sections as parameters for that function (or it ignores them if there are too many).

For example, assume you have the following two functions in your admin controller:

Code:
function more($page) {
    echo "page: $page";
}

function catalog($action, $page) {
    echo "action: $action<br />";
    echo "page: $page<br />";
}

http://code_int.loc/admin/more/2 will output

Quote:action: more
page: 2

http://code_int.loc/admin/catalog/more/2 will output

Quote:more - 2

You'll probably want to define defaults for your parameters because it's possible for a user to go to http://code_int.loc/admin/catalog, which will error out if catalog's $action and $page don't have default values. So you'd instead have:

Code:
function more($page=1) {
    echo "page: $page";
}

function catalog($action='start', $page=1) {
    echo $action.' - '.$page;
}

I highly recommend watching at least the first video tutorial. I was swimming in a world of confusion when I first came to CI: wondering why there were folders listed after our site's index.php file, what the heck all this $this->load stuff was, and more. The hello world video and the parts of the documentation it pointed me to helped immensely.
#5

[eluser]katama[/eluser]
Thank you very much, And I will read documentation one more, I looked it fluently..
But I can't find there example of big url..
I want to do project with a long url such as Site.loc/commercial/residence/flats/buy/2321.
And I was thinking about parsing url by passing segments.. then use several function in site Class and link them by another method, for example..hm, but this is assumption... Confusedhut:
#6

[eluser]James McMurray[/eluser]
Look around the forums some for threads about routing. That might be more what you're looking for.
#7

[eluser]katama[/eluser]
Ok, I will try to find




Theme © iAndrew 2016 - Forum software by © MyBB