Post by jan » Tue Nov 06, 2007 9:06 am

Hi all,

Without further a due "a quick way to get around the aliases that don't work". Version 0.6 (I think).

1) The .htaccess is already already there in the OPC dir, just rename it.
_Just for the record:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
2) Open library->envoriment->request.php
2.1 _Add in the __construct:

Code: Select all

$this->url =& $locator->get('url');
$this->queryToRequest(); 
2.2 _Add to the bottom of the class:
function queryToRequest($query = false) {
if($query == false) {
$data = $this->url->data;
$data = array_flip($data);
$file = basename($_SERVER['REQUEST_URI']);
if($data[$file]) {
$q = $data[$file];
}

} else {
$q = $query;
}

if($q) {

$items = explode('&', $q);
foreach($items as $item) {
$tmp = '';
$tmp = explode('=', $item);
$_GET[$tmp[0]] = $tmp[1];
}
}

return true;
}
!This is just a quick 'n dirty way. I've been up way to long, so I can't guarantee that it's going to hold.

BTW. Is there somekind of reference or documentation?


- cya

jan
Newbie

Posts

Joined
Tue Oct 09, 2007 6:40 am

Post by Daniel » Tue Nov 06, 2007 11:33 pm

I've done an API for the core classes. It will be in the next version.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by tchemis » Wed Nov 07, 2007 12:19 am

Oops, was going to say this does not work for me, just noticed it was for 0.6 I was too excited ;)

Active Member

Posts

Joined
Tue Aug 21, 2007 9:23 am

Post by jan » Wed Nov 07, 2007 6:10 am

Daniel: cool, so aliased urls is standard in the next version?

tchemis: Although...this can be the 0.7 version. At least it has the file structure of 0.7. Can you post some debug info?

jan
Newbie

Posts

Joined
Tue Oct 09, 2007 6:40 am

Post by the311guy » Fri Nov 09, 2007 2:39 am

this fix did not work for me.  I have the latest version.  The shopping cart was looking so good as well :(

Newbie

Posts

Joined
Fri Nov 09, 2007 2:38 am

Post by wesmambo » Thu Dec 27, 2007 9:50 pm

i don't understand, to use a user alias,
can help me

Newbie

Posts

Joined
Mon Dec 24, 2007 11:34 pm

Post by Bogdan I » Mon Feb 18, 2008 7:05 pm

I've come up with a adaptation for 0.7.7
Just change the route function in router.php with this one and it seems the url aliases will work

Code: Select all

function route(&$request) {
		if ($this->path) {
			$path = explode('&', $this->path);
			foreach($path as $item) {
               $tmp = '';
               $tmp = explode('=', $item);
			   $request->set($tmp[0], $tmp[1]);
            }
		}
	}
Still, some testing is needed. Pls. post any errors.

Newbie

Posts

Joined
Mon Oct 29, 2007 4:17 pm
Location - Bucharest

Post by Bogdan I » Wed Feb 20, 2008 4:12 pm

Please allow me to feed-back myself :) The url alias solution for 0.77 I posted a few days ago is working great. I've been testing it till then and no problem appeared. You can see it in action on my website: http://www.beautyspot.ro/produse-pentru ... rea-pielii

Newbie

Posts

Joined
Mon Oct 29, 2007 4:17 pm
Location - Bucharest

Post by Bogdan I » Thu Feb 21, 2008 5:17 pm

I found a little bug and came up with a solution which checks if the requested alias exists in the database. If not, it redirects to homepage. Here it is

Code: Select all

function route(&$request) {		
		$a = $this->database->getRows("select alias from url_alias");
		
		foreach($a as $b){
			$stack[] = $b['alias']; 
		}
		
		$base = explode("/", $_SERVER['REQUEST_URI']);
			
		$last = count($base) - 1;

		$thething = $base[$last];
		
		if(in_array($thething, $stack)){
			if ($this->path) {
				$path = explode('&', $this->path);
				foreach($path as $item) {
	               $tmp = '';
	               $tmp = explode('=', $item);
				   $request->set($tmp[0], $tmp[1]);
	            }
			}
		}
	}

Newbie

Posts

Joined
Mon Oct 29, 2007 4:17 pm
Location - Bucharest

Post by Saberu » Tue Feb 26, 2008 5:37 am

Notice: Undefined variable: stack in /library/application/router.php on line 80

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /library/application/router.php on line 80

edit: Your first solution doesn't error Bogdan. Sorry I'm a bit new to this could you tell me how to get the URI from it? I'll try using the SERVER var URI for now and see if it works.
Last edited by Saberu on Tue Feb 26, 2008 5:58 am, edited 1 time in total.

Newbie

Posts

Joined
Tue Feb 26, 2008 4:30 am

Post by pim » Wed May 07, 2008 5:16 am

hi all

another way for url alias:

1. rename htaccess.txt to .htaccess

2. edit library/application/router.php
change the route function to:

Code: Select all

function route(&$request) {
	if ($this->path) {
		$path = explode('/', $this->path);
		if (isset($this->routes[$path[0]])) {
			$route = explode('/', $this->routes[$path[0]]);
			$i = 0;
			while ($i < sizeof($path)) {
				if (isset($route[$i])) {
					$request->set($route[$i], $path[$i]);
				} else {
					$request->set($path[$i], isset($path[$i+1]) ? $path[$i+1] : NULL);
					$i++;
				}
				$i++;
			}
*		} else {
*			if (!$request->has('controller')) {
*				$path = preg_split("'&|='",$this->path,-1,PREG_SPLIT_NO_EMPTY);
*				while (count($path)>1) {
*					$request->set(array_shift($path),array_shift($path));
*				}
*			}
*		}
	}
}

* edited/new lines

how to use it:
1. goto admin url alias page, and add new alias
example:
url query: controller=account_login
url alias: login

2. goto: http://yourdomain.foo/login and you will see the login page, i hope :)

- works with opencart 0.7.7

pim
Newbie

Posts

Joined
Fri Mar 14, 2008 5:52 am

User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK
Who is online

Users browsing this forum: No registered users and 4 guests