URL adresa hlavnej stranky v nette strukture (treeview)
- derp
- Člen | 4
Ahojte
Potrebujem poradit.
Snazim sa o zmenu URL na stranke, ktora je postavena na Nette
http://www.plaveckaakademia.sk/
Uvodnu stranku presmeruje automaticky na
http://www.plaveckaakademia.sk/sk/intro
(takato je struktura intro stranky v administracii)
Podla vsetkeho pouziva aplikacia TreeView, ak to pomoze.
i ked to v .htaccess presmerovavam akokolvek, vzdy URL ostava taka ako ju nette definuje.
Je mozne nejako zmenit URL hlavnej stranky, aby bola http://www.plaveckaakademia.sk/
Neviem ci je to zalezitost nette framework, ale neviem ked sa inde spytat
Podobne by som z URL chcel odstranit /sk/ pri vsetkych strankach, ktore su v slovencine.
Dakujem za akukolvek odpoved, rad poskytnem dalsie info ked budem vediet ake.
Stranku som neprogramoval, iba som zmenil template na intro stranke
Editoval derp (17. 11. 2011 12:24)
- derp
- Člen | 4
Nasiel som subor DefaultRouter.php
Jeho adresa (od bootstrap.php (app)) je
packages/web/pages/routers/
tu je subor, nenasiel som v nom ale ziadne nastavenia obdobne ako v tutorialy
<?php
class Web_Pages_DefaultRouter extends CallbackRouter
{
public function __construct($mask = '')
{
parent::__construct($mask = '',
array($this, 'in'),
array($this, 'out'));
$this->multilanguage = true;
$this->language = 'sk';
}
function in(IRouter $sender, $slug, $params, IHttpRequest $httpRequest)
{
$cond = '' !== $slug ? array('Page.url=%s AND Language.slug=%s AND Page.active=1', $slug, $params['language']) : array('Language.slug=%s AND Page.active=1', $this->language);
$page = Page::find(array('where' => $cond, 'join' => 'Language', 'orderBy' => 'Page.position ASC'));
if(null === $page) {
return null;
}
else {
if(!Environment::getServiceLocator()->hasService('page')) {
Environment::getServiceLocator()->addService('page', $page);
}
return array(
'presenter' => 'Web:Pages:Default',
'action' => 'default',
'url' => $page->url,
'id' => $page->id);
}
}
function out(IRouter $sender, &$params, PresenterRequest $presenterRequest, IHttpRequest $httpRequest)
{
if(0 !== strpos($presenterRequest->getPresenterName(), 'Web:Pages:Default')) {
return null;
}
if(!empty($params['id']) && !is_numeric($params['id'])) {
$params['url'] = $params['id'];
}
if(isset($params['url'])) {
$url = $params['url'];
unset($params['id'], $params['url'], $params['action']);
return $url;
}
elseif(empty($params['id'])) {
return null;
}
$page = Page::find(array('where' => array('Page.id=%i', $params['id']), 'join' => 'Language'));
if(null === $page) {
return null;
}
unset($params['id'], $params['url'], $params['action']);
$params['language'] = $page->Language->slug;
return $page->url;
}
}
?>
Editoval derp (17. 11. 2011 13:58)
- derp
- Člen | 4
Myslim ze toto je Classa kde sa vytvara URL, ale zatial som tomu nepochopil
<?php
/**
* Callback router
*
* @author
* @package
*/
class CallbackRouter extends Object implements IRouter
{
static $suffixSeparator = '.';
static $suffix = null;
public $language;
public $multilanguage = false;
protected $mask;
protected $matchCallback;
protected $constructCallback;
public function __construct($mask = '', $matchCallback = null, $constructCallback = null)
{
$this->mask= $mask;
if(null !== $matchCallback) {
$this->matchCallback = $matchCallback;
}
if(null !== $constructCallback) {
$this->constructCallback = $constructCallback;
}
}
public function match(IHttpRequest $httpRequest)
{
$path = $httpRequest->uri->path;
$basePath = $httpRequest->uri->basePath;
$slug = preg_replace('#^' . $basePath . '#', '', $path);
$params = $httpRequest->query;
if('index.php' === $slug) {
$slug = '';
}
if(null !== self::$suffix) {
$slug = preg_replace('#' . self::$suffixSeparator . '[a-z0-9\-]+$#', '', $slug);
}
if($this->multilanguage) {
if(preg_match('#^([a-z]{2})/(.*)#', $slug, $matches)) {
$params['language'] = $matches[1];
$slug = $matches[2];
$this->language = $params['language'];
}
else {
$params['language'] = $this->language;
}
}
$slug = rtrim($slug, '/');
$result = callback($this->matchCallback)->invokeArgs(array($this, $slug, $params, $httpRequest));
if(null === $result) {
return null;
}
elseif($result instanceOf PresenterRequest) {
if($this->multilanguage) {
$result->params['language'] = $params['language'];
}
return $result;
}
else {
$presenter = $result['presenter'];
unset($result['presenter']);
$params = array_merge($params, $result);
return new PresenterRequest(
$presenter,
$httpRequest->method,
$params,
$httpRequest->post,
$httpRequest->files,
array(PresenterRequest::SECURED => $httpRequest->isSecured()));
}
}
public function constructUrl(PresenterRequest $presenterRequest, IHttpRequest $httpRequest)
{
$presenter = $presenterRequest->presenterName;
$params = $presenterRequest->params;
$uri = $httpRequest->uri->basePath;
$args = array($this);
$args[] = &$params;
$args[] = $presenterRequest;
$args[] = $httpRequest;
$slug = callback($this->constructCallback)->invokeArgs($args);
if('' === $slug || null === $slug) {
return null;
}
if($this->multilanguage) {
if(isset($params['language'])){
$uri .= $params['language'] . '/';
unset($params['language']);
}
else {
$uri .= $this->language . '/';
}
}
$uri .= $slug;
if(null !== self::$suffix && !empty($slug)) {
$uri .= self::$suffixSeparator . self::$suffix;
}
unset($params['action']);
$query = http_build_query($params, '', '&');
if ($query !== '') $uri .= '?' . $query;
return $uri;
}
}
?>
Editoval derp (17. 11. 2011 14:36)
- derp
- Člen | 4
Dik za pprvotne nasmerovanie
nejako som to vyriesil, i ked VELMI nemotornou metodou, ale je to funkcne.
v CallBackRouter som zmenil
<?php
public function constructUrl(PresenterRequest $presenterRequest, IHttpRequest $httpRequest)
{
$presenter = $presenterRequest->presenterName;
$params = $presenterRequest->params;
$uri = $httpRequest->uri->basePath;
$args = array($this);
$args[] = &$params;
$args[] = $presenterRequest;
$args[] = $httpRequest;
$slug = callback($this->constructCallback)->invokeArgs($args);
if('' === $slug || null === $slug) {
return null;
}
if($this->multilanguage) {
if(isset($params['language'])){
if($params['language']!='sk'){
$uri .= $params['language'] . '/';
unset($params['language']);
}}
else {
$uri .= $this->language . '/';
}
}
if($slug !='intro')
$uri .= $slug;
if(null !== self::$suffix && !empty($slug)) {
$uri .= self::$suffixSeparator . self::$suffix;
}
unset($params['action']);
$query = http_build_query($params, '', '&');
if ($query !== '')
if ($query != 'language=sk')
$uri .= '?' . $query;
return $uri;
}
?>