in following function
public static function ToDepartment($departmentId, $page = 1)
{
$link = self::CleanUrlText(Catalog::GetDepartmentName($departmentId)) .
'-d' . $departmentId . '/';
if ($page > 1)
$link .= 'page-' . $page . '/';
return self::Build($link);
}
there is a line
$link = self::CleanUrlText(Catalog::GetDepartmentName($departmentId)) .
'-d' . $departmentId . '/';
I want to know will self:CleanUrlText() will be evaluated first or Catalog:GetDepartmentName will be evaluated first
if Catalog:GetDepartmentName is evaluated first then, I have a confusion,
what purpose does URL cleaning solve,
if I am visiting a page such as http://localhost/tshirtshop/visit###-the-zoo-d2/
then .htaccess is handling the URL ReWriting part,
where d2 will get converted to DepartmentId=2 and internally in all code logic I will use DepartmentId which is an INT , then why CleanURL function is required
The code is given here
1st: Catalog::GetDepartmentName
2nd: self::CleanUrlText
Related
I am having trouble to dynamic the url using codeigniter.
I need to display dynamic URL look like below.
http://example.com/[store-url]
I did that. But when i try to view non-dynamic url like
http://example.com/blog. It accesssing store page only.
So i have wrote in my routes like below and it is working.
$route['blog'] = "blog";
But here my problem is i am having lot pages such as /blog. all pages are pointing the stores pages only including admin control panel
There any solution for that without setting the routes
In the routes.php
First wirte the coding of Dynamic URL
like
include_once (APPPATH . 'helpers/inflector_helper.php');
$path = explode('/', $_SERVER['REQUEST_URI']);
if ($_SERVER['HTTP_HOST'] == 'www.expample.com') {
$controller = $path[1];
} else {
$controller = $path[2];
}
$route[$controller] = plural($controller) . "/view" . ucwords($controller);
$route[$controller . '/list'] = plural($controller) . "/view" . ucwords($controller);
$route[$controller . '/view/(:num)'] = plural($controller) . "/view" . ucwords($controller) . "/$1";
$route[$controller . '/view/(:num)/(:any)'] = plural($controller) . "/view" . ucwords($controller) . "/$1/$2";
I write my static url
$route['login'] = "authenticate_user/index";
$route['validate'] = "authenticate_user/validateUser";
$route['logout'] = "authenticate_user/logout";
I hope this should work.
First lemme tell you what i am trying to achieve here . Suppose there is a url like this http://www.example.com/?id=12345 now what i want is if there is an id parameter available in the url i want to append the same parameter to every url on that page . Opencart has a url library that generates url i am sure you all must be familiar with it too , i found a way to do what i want but it's working at just some random parts of the website like categories url's are generating with id parameter appended to it and other's dont .
here's what i tried so far
File : System/libray/url.php
here's the function
public function link($route, $args = '', $connection = 'NONSSL') {
if ($connection == 'NONSSL') {
$url = $this->url;
}else {
$url = $this->ssl;
}
$url .= 'index.php?route=' . $route;
if ($args) {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
if(isset($_GET['id']))
{
if(!empty($this->request->get['id']))
$url .= '&id='.$this->request->get['id'];
if(!empty($_GET['id']))
{
$url .= '&id='.$_GET['id'];
}
}
return $url;
}
The problem is that not everything uses this method to generate its URLs.
For example, anything to do with banners (e.g. the Carousel module) uses links that the admin sets manually in System->Design->Banners, so you would also need to edit the code for this too. The simplest and probably the correct way is to edit the data that the models spit out e.g.
model_design_banner->getBanner() becomes
public function getBanner($banner_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "banner_image bi LEFT JOIN " . DB_PREFIX . "banner_image_description bid ON (bi.banner_image_id = bid.banner_image_id) WHERE bi.banner_id = '" . (int)$banner_id . "' AND bid.language_id = '" . (int)$this->config->get('config_language_id') . "'");
if (isset($_GET['id'])) {
array_walk($query->rows, function(&$value) {
$value['link'] .= '&id=' . $_GET['id'];
});
}
return $query->rows;
}
It's either that, or edit the output in every single controller that uses this method.
That's just an example for banners, though. I don't recall off-hand which other modules will need to be edited, but if there's a particular one that's making you scratch your head, let me know and I'll give you another example to fix it.
i´m trying to include some code from the own server via an api / brigde / whatever...
class ZKBrigde {
private $_url;
public function __construct() {
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$script = explode('/', $script);
array_pop($script);
$this->_url = "http://" . $host . implode('/', $script) . '/zk/';
}
Here i´m looking for the main url of the target framework.
In an request im using this (example, $items is an integer):
return file_get_contents($this->_url . "brigde/acp/page/changelog/$items");
First, this has worked. In some cases if i have an error in my code, it don´t work, returns false. OK, i´ve fixed the errors.
Now, changed some code of the backend, it doesnt work.
If i type the URL in my browser, i get the required result, no errors.
With this now i always get the result "FALSE".
How to check what is wrong?
Any hints to make it better?
(It should be an API / Brigde to my CMS)
lg., Kai
Try this:
$this->_url = trim("http://" . $host . implode('/', $script) . '/zk/');
And try if the URL are clear and in a good format!
class ZKBrigde {
private $_url;
public function __construct() {
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$script = explode('/', $script);
array_pop($script);
$this->_url = trim("http://" . $host . implode('/', $script) . '/zk/');
$open = open("test.txt", "w");fwrite($open, $this->_url);fclose($open);
}
Take a look in test.txt when you've tested the script.
According to PHP's documentation if your path has special characters and you are trying to open an URI, then you need to use urlencode() function. Does your path have special characters? I'd use urlencode to be in the safe side.
http://us1.php.net/file_get_contents
Newb here working on refining a function to deliver a better user experience.
My goal is that if we are not on the index page (home) of the site, i wish to include a link to return to the home page. But if we are on the index page (Home), i don't wish to display the redundant link in the menu. Below is the function I've built, which you can see here 'school.max-o-matic.com'. at the bottom of the right navigation menu is a link that reads '< back' which should not show on the index page but should ideally show on all other pages.
I'd hoped the use of the exclamation point followed by an equal sign would do the trick but it did not.
<?php
function makeNav($navItem) {
//created variable - plops in what is called when function used on
//page calling the function itself - this is like the strPromp
$output = ''; //Variable of 0 length
foreach ($navItem as $pageLink => $displayedLink) {
if ($pageLink == THIS_PAGE) {
//url matches page - add active class
$output .='<li class="active">'
. '' . $displayedLink . ''
. '</li>' . PHP_EOL;
} //PHP_EOL is php line end for all systems
else {//don't add class
$output .='<li>'
. '' . $displayedLink . ''
. '</li>';
}
}
if ($pageLink != 'index.php') {//add back button to index page
$output .='<li>'
. '< Back'
. '</li>' . PHP_EOL;
} //PHP_EOL is php line end for all systems
$output .='<li>'
. 'contact'
. '</li>';
return $output;
}
?>
if($_SERVER['PHP_SELF'] != '/index.php'){ //process if file is not index file.
}
to exclude access to index file.
if (strpos($_SERVER['PHP_SELF'],'index.php') !== false) { //process if file contains text "index.php" in filename.
}
//to exclude access to any file with name containing "index.php" file
if (basename($_SERVER['SCRIPT_NAME']) != 'index.php'){
//run on all files that ARE NOT index files in any folders.
}
You could check this by using the $_SERVER global variable, which is an array of request information. The key 'SCRIPT_NAME' contains the path to the requested file. The check on this could be:
if (basename($_SERVER['SCRIPT_NAME']) != 'index.php') {
I have the PHP code:
$uid = $xUS['id']; // Current user id
$uname = $xUS['x_username']; // Current user name
$ulink = ''; // Current user profile URL (leave blank for none)
$upic = $xUS['config_forum_avator_head']; // Current user
$ismod = 0; // Is current user a moderator?
$sig = md5($uid . $uname . $ismod . 's79tvi40k95bs6mw');
$ssoParams = '&uid=' . $uid . "&uname=" .
urlencode($uname) . "&ulink=" . urlencode($ulink) . "&upic=" . urlencode($upic)
. "&ismod=" . $ismod . "&sig=" . $sig;</i>
My Smarty template file:
<iframe width='550' height='500' src='http://chatroll.com/embed/chat/pibux-chatroom?id=tgybumotNmY&platform=php{$ssoParams}&w=$0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>
In this, the {$ssoParams} variable is returning a null value. Why? Please help out.
Read Smarty docs for example: http://www.smarty.net/docsv2/en/language.variables.tpl#language.assigned.variables
You need to assign a variable like:
$smarty = new Smarty();
$smarty->assign('ssoParams', $ssoParams); // assign(smarty var, PHP var);
$smarty->display('template_file.tpl');
And of course you need to include smarty files, define templates etc.
For basic working example look example 2.9. here:
http://www.smarty.net/docsv2/en/installing.smarty.basic.tpl#id2778275