ZF2 Friendly URL + SEO - php

I have two questions for you:
1) I'm developing my website in ZF2, and I want to make a friendly URL like:
domain.com/ADFE4
domain.com/RURUR
domain.com/UYRRTG
with a variable second part. The problem is that ZF2 interpret this second url like a controller. How could I send this url parameter to index action in the index controller?
2) This way to make the site, could be bad for SEO? Not for the friendly url,
but the same controller for manage the route.

try to use router like this:
'friendlyPage' => array(
'type' => 'segment',
'options' => array(
'route' => 'sometext-[:param]',
'constraints' => array(
'param' => '[0-9]+',
),
'defaults' => array(
'controller' => 'ControllerName',
'action' => 'ActionName',
),
),
),

Related

ZF2- Dynamic base route

I'm trying to create a dynamic route in a ZF2 project. It will be something like "domain.com/companyurl/products". The company url is dynamic. I did it:
'company' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:company]',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
...
),
),
But I always have to pass the company parameter in a route.
$this->url('company/products', array('company' => 'companyurl'));
Is there some way to specify a base route at the runtime, like a base url, then all route will follow it? Something like this:
$this->url('products');
or
$this->url('company/products');
In the both cases I already specified the base route value.
I hope you understand what I mean. Thanks.
There is a $reuseRouteParams option that you can use in the URL helper:
$this->url($name, $params, $options,$reuseMatchedParameters);
If you set this to true it will reuse the previous route match value of companyUrl.
You can read more on this in the docs here.

How to set up callback URL in ZF2 from Paypal?

I am trying to use Paypal express checkout from my Zend framework (version 2.4) application.
The callback URL is set to http://localhost/tjla/store/payment-confirm.php
There is a function in StoreController.php called paymentConfirmAction
The child route in my module.config.php looks like:
'store' => array(
'type' => 'Segment',
'options' => array(
'route' => '/store[/:action]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Tjla\Controller\Store',
'action' => 'index',
),
),
),
When the Paypal action completes it calls back with http://localhost/tjla/store/payment-confirm.php?token=xxxxxxxxxxx&PayerID=xxxxxxxxx
But this generates a 404 Page Not Found error
What am I missing/doing wrong?
If your action is paymentConfirmAction, http://localhost/tjla/store/payment-confirm?token=xxxxxxxxxxx&PayerID=xxxxxxxxx should match your route. The .php does not, which is why you're currently getting a 404.

How to pass parameters by url with Zend Framework 2

I'm getting into trouble with passing param by url in Zend Framework 2. For example : I want to access page by a URL like this:
http://example.com/student/details/aaa it's working, but if my url like this :
http://example.com/student/details/1 it's not working, And i still get a 404.
I tried to follow the instruction from how to pass params using a route in Zend Framework 2?
But it still doesn't work.
here's my module.config.php
'student' => array(
'type' => 'segment',
'options' => array(
'route' => '/student[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'__NAMESPACE__' => 'AppFeeder\Controller',
'controller' => 'Student',
'action' => 'index',
),
),
),
And i use this $this->getEvent()->getRouteMatch()->getParam('id') in my controller.
Can anyone help me ?
You are using wrong route rule for id which says start from alphabet then alphabet+number+"_-".
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
Instead you need to change the rule that says start from alphabet+number then alphabet+number+"_-"
'id' => '[a-zA-Z0-9][a-zA-Z0-9_-]*',

Zend Framework 2 navigation active class with params

Hi I have create a route like this
'webb' => array(
'type' => 'Segment',
'options' => array(
'route' => '/oferta/[:url1[/:url2][/:url3][/:url4]]',
'defaults' => array(
'controller' => 'webb',
'action' => 'index',
),
),
So my route is looking for paremeters url1 url2 etc
I have created navigation like this (just one item to show)
'page-3' => array(
'label' => 'example',
'route' => 'webb',
'controller' => 'index',
'params' => array('url1' => aa', 'url2' => bb', 'url3' => 'cc'),
)
and when I am rendering it using zend navigation helper everything is working fine despite that the current class of item is not changing to active? Any ideas? could it be done this way or when I am passing params zend navigation will not change class?
Bur url is bulid fine i get something like this /oferta/aa/bb/cc
Please help
Remove controller key from navigation array and it should work ('controller' => 'index' is wrong anyway).
From zend.navigation.pages.mvc
Note that when using the route property in a page, you do not need to specify the default params that the route defines (controller, action, etc.).

Zend Framework 2, redirecting to route and passing a variable to new controller

I implemented a form for placing new orders in Zend Framework 2 and after submitting the form I should redirect to another route and take the orders.id variable in another controller.
I tried using $this->redirect()->toRoute('confirm', array('param'=>$orderId)); but it is not working at all.
Maybe I do not know how to get that parameter in another confirmAction controller.
Please give me some examples. Thank you very much.
1) Since this is a routing issue, show what you have for the route in the module.config.php file. You might not have the "param" constraint configured properly in your config if I had to guess.
It should look something like this:
'confirm' => array(
'type' => 'segment',
'options' => array(
'route' => '/controller_name/confirm[/][:param][/]',
'constraints' => array(
'param' => '[0-9]*'
),
'defaults' => array(
'__NAMESPACE__' => 'your_namespace', // ex. Application\Controller
'action' => 'confirm', // or whatever action you're calling
'controller' => 'controller_name' // ex.
),
),
),

Categories