MVC 패턴을 사용하여 Silex로 앱을 작성합니다. 나는 경로 수집을 한 후에 내가해야 할 일에 관해서 약간의 문제가있다. 당신은 내가 몇 가지 기본 PARAMS을 설정할 볼 수컨트롤러로의 Silex 라우팅
<?php
namespace App;
use Igorw\Silex\ConfigServiceProvider;
use Silex\Application as Silex;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class Bootstrap extends Silex
{
public function __construct()
{
$this['debug'] = true;
$this->registerDefaultParameters();
$this->registerDefaultServices();
$this->registerRoutes();
}
protected function registerDefaultParameters()
{
$paths = isset($this['base_path']) ? $this['base_path'] : array();
if (!isset($paths['base'])) {
$paths['base'] = realpath(__DIR__ . '/../');
}
$defaults = array(
'config' => $paths['base'] . '/App/Config',
'twig.path' => $paths['base'] . '/public/themes/base/templates'
);
foreach ($defaults as $key => $value) {
if (!isset($paths[$key])) {
$paths[$key] = $value;
}
}
$this['paths'] = $paths;
}
protected function registerDefaultServices()
{
$this->register(new ConfigServiceProvider($this['paths']['config'] . "/Services.yml"));
foreach($this['services'] as $serviceName => $serviceData)
{
$this->register(new $serviceData['class'],(array_key_exists('parameters',$serviceData)) ? $serviceData['parameters'] : array());
}
}
protected function registerRoutes()
{
$this->register(new ConfigServiceProvider($this['paths']['config'] . "/Routes.yml"));
$collection = new RouteCollection();
foreach($this['routes'] as $key => $value)
{
$collection->add($key, new Route(
$value['path'],
$value['defaults'],
array(),
array(),
null,
null,
$value['methods']
));
}
$this['routes'] = $collection;
}
}
그래서 :
다음은 응용 프로그램 내 부트 스트랩입니다. 또한 잘 작동하는 YAML 파일에서 내 서비스를로드합니다. 그런 다음 YAML 파일에서 내 경로를 다시 등록합니다. YAML 파일의 각 경로를 반복하고 RouteCollection에 경로를 추가 한 다음 해당 경로를 apps [ 'routes'] 엔티티에 다시 저장합니다.
그래서 $ this [ 'routes']는 'RouteCollection'의 인스턴스이고 내 모든 경로는 그 안에 'Route'인스턴스로 있습니다.
이제 경로에 대한 모든 컨트롤러를 설정하고 싶습니다. 내 문제는 가능한 모듈화 된 제품을 설정하는 것입니다. 그래서 모든 컨트롤러와 모든 모델이 들어있는 컨트롤러 폴더와 모델 폴더 대신 모든 코어 모듈이 포함 된 코어 폴더를 갖고 싶습니다. 베이스 모듈, 페이지 모듈 및 접촉 모듈을 포함 할 수있다. 각 모듈에는 자체 컨트롤러 모델 뷰 등이 있습니다. Magento 코어와 매우 유사합니다.
그래서 제 질문은 :
는지금은 내 경로가 설정 한 어떤 단계 난 내 경로가 올바른 컨트롤러와 액션의 인스턴스를 만들기 위해 수행해야합니까?
나는 이것을 동적으로 필요로하므로 각 컨트롤러를 선언하지 않을 것이다.
도움이 될 것입니다.