Specifying domain in zend view url-helper - php

My application has two modules Product module and Blog module. Both modules use the same DB. There are two domains: the first pointing to the Product Module (www.mainsite.com) and the second to the blog module (www.blog.mainsite.com). There will be multiple links connecting from the Product Module and Blog module.
The issue is that i am using the zend url view helper. But i was not able to specify the domain to that view helper. when i call the view helper it is always returning my current domain. I have checked the zend framework manual, but nothing was found.
Is there any other option in zend to implement the same?

In case of fully qualified URI you should go for:
$this->_redirect('http://www.blog.mainsite.com/some/thing');
When you are calling the url helper in a view it actually calls route assembler. So I assume you should define two routes for each domain and use the view helper something like that:
echo $this->url (array ('action' => 'some', 'controller' => 'thing'), 'routeName');

You can try this- http://framework.zend.com/manual/1.12/en/zend.controller.router.html#zend.controller.router.routes.hostname (not tested)
You can also just concat $_SERVER['HTTP_HOST'] with the URL generated by URL view helper.

Use the ServerUrl view helper, along with the "//" notation for inheriting the current URL scheme:
echo '//' . $this->serverUrl() . $this->url(/* ... */);

Related

Display dynamic URLs in CodeIgniter for seo

I'm building an online store based on CodeIgniter. I'd like URLs to look like this? What is the solution for this type of SEO friendly url.
http://example.com/[product-category]/[product-sub category]
I need this url:
example.com/women/sarees-sari
But my url is generated
example.com/Product/item/MQ==/women/sarees-sari
/Product/ is my controller,
/item/ is function name,
/MQ==/ is my product id
You can use routing to handle your request url. It's simple. For example for your case:
$route['women/sarees-sari'] = 'Product/item/MQ==';
Codeigniter has _remap function that can be called on controllers. So you can call this on core controller or main controller, and call your function that wish.
CodeIgniter has very good routing System so you can modify your url as per your requirement and linking using /application/config/routes.php file.
If you open this file first time, you will see only default controller, i.e $route['default_controller'] = 'welcome';
but you can add as many routes as you want. Like in your case for seo, you should add
$route['women-sarees-sari'] = 'Product/item/MQ=='; and this will route the user from www.example.com/women-sarees-sari to correct controller and method.

Yii2 yii\helpers\Url helpers Url to another site

I am using yii\helpers\Url helpers to access my site's urls in menu. But there should be a url goes to another site, like www.anothersite.com/action.
How can I place this link via yii\helpers\Url helpers ?
Is it possible to add a url that goes other site with yii2 yii\helpers\Url helpers ?
This soultion is reusable, so give a try.
Define an alias inside application's config file.
Yii::setAlias('#another', 'http://anothersite.com/action');
Then you'll be able use it throughout entire application like,
//assuming you've already imported yii\helpers\Url
Url::to('#another');
Yup, just like this:
<?= \yii\helpers\Url::to('http://www.anothersite.com/action') ?>
But this is the same as:
<?= 'http://www.anothersite.com/action' ?>
If you want to use routes there for another website (so you can use array route with action parameters for example) you need to configure first the urlManager for the other site, otherwise it will not work.

Custom routes with a different base URL in Cakephp using Router/HtmlHelper

I'm running a CMS using CakePHP at an URL like https://cms.example.com
In the CMS, we have links to view/preview content entered on the site. But the preview links are hosted on the front facing website: http://www.example.com.
I'm using the HtmlHelper::link() method to generate the URLs with reverse routing by sending it an array of parameters. This works fine other than the fact that the base url is wrong. It looks like HtmlHelper is just some extra code wrapped around Router::url(), which does its own lookup of the 'base' url value.
Is there some easy way to override this value? I have separate config files for each environment (dev, staging, production) that I can use to set a base url value for these types of links, but it doesn't appear that passing in 'base' does anything in the Router class.
I was considering overriding or creating an extra function extending HtmlHelper but if the route itself is handled by Router I'd now have to override/extend that instead, which seems like a mess.
HtmlHelper::link's $url parameter references $this->url() to parse the value. There is no url() method in HtmlHelper, though. It is inherited from the Helper class, where it is defined as:
public function url($url = null, $full = false) {
return h(Router::url($url, $full));
}
So really, it's just a wrapper around Router::url(), which has no ability to modify the base url. There is logic in Router to look up the base url, but no ability for the user to modify it without overloading Router.

Zend framework Router replaces capital letters with dashes by default?

If we use capital alphabet in between name for zend controller and action for example inside default module we create
class MyGoodController extends Zend_Controller_Action {
public fooBarAction()
{
}
}
Than to access this action browser url looks like mysite.com/my-good/foo-bar
Is there any default zend router added inside zf managing this translation ?
because I want to use URL view helper to generate the correct link for me which it doesnt for e.g in view
$this->url(array('action'=>'fooBar','controller=>'myGood'));
did not produce the correct url it generates /myGood/fooBar instead of /my-good/foo-bar
As stated in the comment you need to use:
$this->url(array('action'=>'foo-bar','controller=>'my-good'));
The URL view helper assembles a link based on a route set in your application.
Routes match requests based on the URL.
It really comes down to separation of concerns. The helper is only making use of a route and again routes only deal with what is in the URL. Getting the proper class names based on a route is the dispatcher's concerns.
It's best to leave the route to deal with only what is in the URL because dispatchers can change. What might work for you using the standard dispatcher may not fit others that use a different dispatcher.
To accomplish what you're asking, you can always use a custom view helper that does the conversion for you but that is assuming you never change dispatchers.

How to implement keyword specific page invocation using PHP codeigniter

How to implement keyword specific page invocation using PHP codeigniter
Binary search Tree Implementation.
for e.g. in above URL keyword "binary-search-tree-implementaion" is method name or parameter for specific controller. because most of things are dynamic then how web site is going to manage all those things?
I want to implement it for my web site like this
http://example.com/search/digital-camera-price-in-india
I'm not familiar with CodeIgniter, but usually a URI structure like /search/digital-camera-price-in-india would route to the Search controller and digitalCameraPriceInIndia action.
/search/digital-camera-price-in-india
=> SearchController::digitalCameraPriceInIndiaAction()
If you want to route similar URIs (different products for example) to a catch-all method, you've have to setup custom routing.
The CodeIgniter documentation for routing is here
As per #chriso's answer you will need to set up a custom route to achieve this as by default the uri structure is /controller/action/params. So in your config/routes.php file you can add something like:
$route['search/(:any)'] =
"search/some_action";
And then use the relevant uri segment (
$this->uri->segment[1]
I think) as your search parameter.
if you set up your route like this:
$route['^search/(:any)'] = "search/my_controller_function/$1";
Then you can just write your function like this:
public function my_controller_function($search_input)
{
// your code here
}

Categories