-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I use a parameter in the index function? it shows me an error #52
Comments
There are two way of doing this:
1> Using $_GET method
URL=> www.example.com/user/index/?id=1&status=fail
In function =>
public function index()
{
//do some validation on $_GET using isset() function
$id=$_GET['id'];
$status=$_GET['status'];
}
2> Using parameter method
URL => www.example.com/user/index/2/fail
In function=>
public function index($id=0,$status="")
{
}
Let me know if this works for you. Share your piece of code for better
understanding if not working above solution.
…On Sun, Nov 10, 2019 at 7:45 AM Jose Cayo ***@***.***> wrote:
it shows me an error
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/BABAERON/PIP/issues/52?email_source=notifications&email_token=AD76OYVHYXAHQYOCPNNFGILQS5VFBA5CNFSM4JLKP3JKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HYG27GA>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD76OYQUQXZS7DJMRGFJOALQS5VFBANCNFSM4JLKP3JA>
.
--
Cheers!
Karan Sapkale
|
there is a way to use as in other frameworks that receive an index parameter without problems |
Well you can do only one thing here.
Just rename your index action to other useful name (ie. fetch, list, etc)
Hard solution:
Push "index" in segments array in pip.php when current controller is 'user'
And then you can use it like you want.
Let me know if you need that piece of code.
…On Tue, 12 Nov, 2019, 11:20 Jose Cayo, ***@***.***> wrote:
there is a way to use
domain.com/user/2?
and not
domain.com/user/index/2
as in other frameworks that receive an index parameter without problems
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/BABAERON/PIP/issues/52?email_source=notifications&email_token=AD76OYVWKR5YMCHDCMMYO5LQTI72HA5CNFSM4JLKP3JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDZDTFI#issuecomment-552745365>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD76OYRBBRMRXMT2GOKOEITQTI72HANCNFSM4JLKP3JA>
.
|
this is my pip.php |
Hi,
Here what I did:
I have added *$sliceOffset *variable with *default value = 2* // which
identifies your parameter position in segments array at the end of your code
and based on your current controller position in segments array, I have
adjusted the parameter slicing offset value, which will be used at the end
code where *call_user_func_array() *function is getting called.
Just try, and let me know if it works for you or not.
*#line 51>*
if(isset($segments[0]) && $segments[0] != '') $controller = $segments[0];
if(isset($segments[1]) && $segments[1] != '') $action = $segments[1];
// Get our controller file
$path = APP_DIR . 'controllers/' . $controller . '.php';
$sliceOffset=2; <===ADD THIS VARIABLE
*#line 71>*
$path = APP_DIR . 'controllers/' . $directory."/".$controller . '.php';
if(file_exists($path)){
$sliceOffset=3; <===UPDATE THIS VARIABLE
*#line 86>* if(!method_exists($controller, $action)){
$controller = $config['error_controller'];
require_once(APP_DIR . 'controllers/' . $controller . '.php');
$sliceOffset =1; <===UPDATE THIS VARIABLE
$action = 'index';
}
*#line 184>*
// Use below code
// Create object and call method
$obj = new $controller;
die(call_user_func_array(array($obj, $action), array_slice($segments,
$sliceOffset)));
…On Tue, Nov 12, 2019 at 11:06 PM Jose Cayo ***@***.***> wrote:
this is my pip.php
https://codeshare.io/jGzQ9
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/BABAERON/PIP/issues/52?email_source=notifications&email_token=AD76OYR23NH4ION7BEQ22CDQTLSQLA5CNFSM4JLKP3JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED3CVNI#issuecomment-553003701>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD76OYTL2D7T4AS2ZTHXJY3QTLSQLANCNFSM4JLKP3JA>
.
--
Cheers!
Karan Sapkale
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it shows me an error
The text was updated successfully, but these errors were encountered: