Welcome Guest, Not a member yet? Register   Sign In
I am this close to give up on CI
#1

[eluser]KevinLG[/eluser]
CI could put this line in the first page of the manual:
"If your hosting service does not support the PATH_INFO variable needed to serve search-engine friendly URLs, then for your mental health's sake you better not use Codeigniter."

That would have saved me 4 miserable hours.

OK, sorry.

I have set up these:

Code:
$config['index_page'] = "index.php?";
$config['uri_protocol'] = "QUERY_STRING";
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

My controller file is delme.php:

Code:
<?php
class Delme extends Controller {
  function index() {
    echo 'Hello!';
  }
  function greeting($name,$times){
    for ($i=0;$i<(int)$times;$i++) {
      echo 'Hello '.$name.', from subfolder!';
    }
  }
}
?&gt;

This controller is placed in a subfolder 'test' of the 'controllers' folder.

My question is what URL I should use to access this "greeting" method?

The url "http://www.my-site.com/index.php?/test/c=delme&m=greeting&name=kevin&times=5" just refused to work. I know why, because I made that sh*t up! And I tried numerous other wierd combinations. Where is the explanatin in the touted excellent manual about this?

Thanks for your help. A newbie's frustration, forgive me please.
#2

[eluser]xwero[/eluser]
There is a hosting service that doesn't support path_info ??? Even free hosters allow path_info. I even believe it's a part of the http protocol.

The first mistake you made is the question mark for the index_page. If there is a querystring the question mark will be added automatic.

The second mistake is not having a constructor in your controller
Code:
class Delme extends Controller {

function Delme()
{
    parent::Controller();
}

function index() {
echo 'Hello!';
}

function greeting($name,$times){
for ($i=0;$i<(int)$times;$i++) {
echo 'Hello '.$name.', from subfolder!';
}
}
}

The third mistake is your url. I don't know how the querystring is if you put the controller in a subfolder but i guess the url would look more like

http://www.my-site.com/index.php?c=test&...in&times=5

Try the controller in the controller directory with the url

http://www.my-site.com/index.php?c=delme...in&times=5

This should work
#3

[eluser]KevinLG[/eluser]
Hi Thanks for the help, but it's still not working. I followed your three suggesstions, also, I put the delme.php in the "controllers" folder. The error message when accessing http://www.my-site.com/index.php?c=delme...in&times=5 is:

A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for greeting()
Filename: controllers/delme.php
Line Number: 14

A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for greeting()
Filename: controllers/delme.php
Line Number: 14

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: times
Filename: controllers/delme.php
Line Number: 16


btw, access to http://www.my-site.com/index.php?c=delme&m=index is ok.

Basically my questions simply are
[b]1.
how to pass multiple parameters to a method in controller, under my configration (please see the first post)?
2. if the controller is in a sub-folder of the "controllers" folder, then how to pass parameters to a method in that controller?

Thanks.
#4

[eluser]Dready[/eluser]
hello,

you need to catch variables from PHP global variable $_REQUEST :

Code:
function greeting($name = '',$times = ''){
if ( isset($_REQUEST['name']) ) {
  $name = $_REQUEST['name']
}
if ( isset($_REQUEST['times']) ) {
  $times = $_REQUEST['times']
}


for ($i=0;$i<(int)$times;$i++) {
echo 'Hello '.$name.', from subfolder!';
}
}

and then use http://www.my-site.com/index.php?c=delme...in&times=5
#5

[eluser]KevinLG[/eluser]
You rock! That works. I was thinking I could use something similar to params[...] stuff. But I am happy with this too!

Can someone help me with this subfolder controller thingy(what's the URL for a controller in a subfolder)? Many thanks.
#6

[eluser]Dready[/eluser]
Looking at the code in version 1.5.4 you can't do it without modification to the core of the framework.
#7

[eluser]worchyld[/eluser]
Using global $_REQUEST is dangerous.
#8

[eluser]Majd Taby[/eluser]
don't use $_REQUEST, it's a bad idea, $_REQUEST gets anything (post, cookie, get), all of which can be tampered with.




Theme © iAndrew 2016 - Forum software by © MyBB