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.
Related
Hello I'm currently working with php to generate a menu with a own build CMS system.
I'm making a dynamic link with : $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."/";
Than I'm adding . $row_menu['page_link'] from the database. At first it works perfect:
as example =
$row_menu['page_link'] = page2;
$url . $row_menu['page_link'];
it will return as example : http://example.com/page2
But when I click again, it adds page2 again like : http://example.com/page2/page2
How do i prevent this?
Thanks in advance!
Because at first time your $_SERVER['REQUEST_URI'] will be like http://example.com but when the user click on the link then the value of $_SERVER['REQUEST_URI'] would become http://example.com/page2.That's why it is appending two times.
Instead you can use HTTP_REFERER like
$url = $_SERVER['HTTP_REFERER'].$row_menu['page_link'];
Considering that your $_SERVER['HTTP_REFERER'] will results http://example.com.Also you can try like
$protocol = 'http';
$url = $protocol .'//'. $_SERVER['HTTP_HOST'] .'/'. $row_menu['page_link'];
REQUEST_URI will give you whatever comes after example.com, so leave that out all together.
$url = $_SERVER['HTTP_HOST'] . "/" . $row_menu['page_link'];
You can find a full list of the $_SERVER references here.
Try this:
$requested_uri = $_SERVER['REQUESTED_URI'];
$host = $_SERVER['HTTP_HOST'];
$uri_segments = explode('/',$requested_uri);
$row_menu['page_link'] = 'page2';
if($row_menu['page_link'] == $uri_segments[sizeof($uri_segments)-1]) {
array_pop($uri_segments);
}
$uri = implode('/',$uri_segments);
$url = 'http://'.$host.'/'.$uri.'/'.$row_menu['page_link'];
echo $url;
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 working with an custom back-end template in Joomla and now I'm come to a point that I need to support multiple languages.
In the begin of the development I did not think about multiple languages and that gives me some trouble now. That it is best to rewrite the code and make it "smarter" I know, but at this point there is not much time to rewrite this code.
In the backend I'm working with icons that are based on the page title. For example the page Article Manager requests the icon images/icon/article-manager.png. So you see what happens if the page title is for example German and is called Inhalt.
At this moment I use this code to generate the iconpath:
#Loading Joomla Document Module
$doc = JFactory::getDocument();
#Get the page title
$title = explode("-", $doc->title);
$title = trim(end($title));
#Generate icon path
$lastTitle = explode("-", $title);
if (strpos(end($lastTitle), ':')) {
$lastTitle = explode(":", end($lastTitle));
$lastTitle = $lastTitle[0];
$iconPath = trim($lastTitle);
$iconPath = 'templates/' . $this->template . '/images/icons/' . strtolower(str_replace(" ", "-", $iconPath)) . '.png';
} else {
$iconPath = trim(end($lastTitle));
$iconPath = 'templates/' . $this->template . '/images/icons/' . strtolower(str_replace(" ", "-", $iconPath)) . '.png';
}
Now I'm thinking of searching the database for the page/componetent/modul/plugin ID but is there a faster/easier way to edit it?
Work around
As earlier stated, icons generated by a page title is indeed a bad idea. But Lodder came with a pretty nice and easy work around. So I decided to follow his idea. I added an extra variable that checks if it is a 'subpage', when yes then it extends the icon file name with this subpage.
#Loading Joomla Application Module
$app = JFactory::getApplication();
#Genrate page icon
$comp = $app->input->get('option');
$view = $app->input->get('view');
if(!empty($view)) {
$iconFileName = $comp . '-' . $view;
} else {
$iconFileName = $comp;
}
$iconPath = 'templates/' . $this->template . '/images/icons/' . $iconFileName . '.png';
Basing the icons on the Page Title is a bad idea. Purely because as you have already mentioned, your site is multi-lingual, therefore different languages will result in different results.
I would personally base the icons on the component name. For example:
$jinput = JFactory::getApplication()->input;
$view = $jinput->get('option');
The above code will output com_content and will always be the same for all languages.
You can then simply name your icon com_content.png and call the icons like so:
$iconPath = 'templates/' . $this->template . '/images/icons/' . $view . '.png';
Hope this helps
I would like to get all of the base url of the site in my twig extension:
$this->service_container->get('request')->getBaseUrl()
gives me a lot but the host is missing...
another method maybe to get everything or one to get the host ?
Goal : have this :
http://my_host/request_base_url
$request = $this->getRequest();
$scheme = $request->getScheme();
$host = $request->getHttpHost();
$base = sprintf('%s://%s', $scheme, $host);
This is how im using this code to get complete base url .
public function test($request){
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() ;
}
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