Skip to content
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

Parameter Patterns #10

Closed
dukinfotech opened this issue Jan 9, 2019 · 10 comments
Closed

Parameter Patterns #10

dukinfotech opened this issue Jan 9, 2019 · 10 comments

Comments

@dukinfotech
Copy link

Hi izniburak, thank your contribution for our community. I try using parameter patterns feature. But it not working. It shows Object not found!. URL: '/' is working perfectly. Thank
$router->get('/', function() {
echo 'Home';
});

$router->get('/{s}', function($value)
{
echo 'Hello, ' . $value;
});

@peter279k
Copy link
Contributor

peter279k commented Jan 9, 2019

@dukinfotech, thank you for your reply. I can use the parameter pattern successfully.

Here is my sample code:

<?php

require __DIR__ . '/../../vendor/autoload.php';

use Buki\Router;

$params = [
    'paths' => [
        'controllers' => 'controllers/',
    ],
    'namespaces' => [
        'controllers' => 'Controllers\\',
    ],
    'base_folder' => __DIR__,
    'main_method' => 'main',
];

$router = new Router($params);

$router->get('/', function() {
    return 'Hello World!';
});


$router->get('/{s}', function() {
    return 'parameter pattern';
});

$router->get('/controllers', 'TestController@main');

$router->run();

You can save this file named server.php and run php -S localhost:5000 tests/fixtures/server.php and type the localhost:5000/string url on the browser.

I use the php-7.2 to complete this work.

Can you reproduce issue? Thanks.

@dukinfotech
Copy link
Author

dukinfotech commented Jan 9, 2019

I find out why it not working. My project is subdir: htdocs/mvc-base. But i don't know how to fix
Can you share me code for .htaccess file and index.php for subdir

@peter279k
Copy link
Contributor

peter279k commented Jan 9, 2019

@dukinfotech, you have to change the original web document root to htdocs/mvc-base.

And it will be worked fine.

It looks like you use the XAMPP server? Please look at this reference.

@dukinfotech
Copy link
Author

dukinfotech commented Jan 9, 2019

What happens with other project in htdocs folder if changing xampp document root. I just want to use for mvc-base project. Does it overide by .htaccess file or some php code?

@izniburak
Copy link
Owner

@dukinfotech Are you sure that you set base_folder value in configuration parameters correctly?

@peter279k
Copy link
Contributor

peter279k commented Jan 9, 2019

@izniburak, I think it's not related to the base_folder problem.

This issue is about the Deployment.

To solve this issue, it should have the build/deployment tutorial.

@peter279k
Copy link
Contributor

peter279k commented Jan 9, 2019

BTW, I also deploy this router with Apache server on Linux Ubuntu 16.04 successfully.

It's about the internal Apache setting, including .htaccess and rewrite setting.

@izniburak
Copy link
Owner

I guess so. Rewrite module must be enable for Apache on the server. After that, .htaccess file must be add. Documentation may help to you.
https://github.com/izniburak/php-router/wiki/2.-Getting-Started#quick-usage

I just made a new test to make sure. No problem occurred.

@dukinfotech
Copy link
Author

dukinfotech commented Jan 10, 2019

Tks all!. My problem's about .htaccess file. I just copy content of .htaccess file. But now i need tutorial for setting multi folder controller? frontend/controllers and backend/controllers. How to do that?

@izniburak
Copy link
Owner

@dukinfotech You can not do like this. But you can try to do this:

controllers/frontend
controllers/backend

And you should add namespace definition in your controller classes. For example:

# this class in controllers/frontend
namespace Controller\Frontend;
class HomeController {
  //
}

# this class in controllers/backend
namespace Controller\Backend;
class HomeController {
  //
}

Finally, you can update Route definition like this:

$route->get('/backend-home', 'Backend.HomeController@main');
$route->get('/frontend-home', 'Frontend.HomeController@main');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants