Html->link in home page to another controller action - hyperlink

I'm trying to link a controller action in my home page. this is what i wrote:
<?php $this->Html->link(__('Assign', array('plugin' => 'full_calendar',
'controller' => 'events',
'action' => 'assign',
$events['Event']['id']
)
)
); ?>
but when the home page renders, the button label is /pages/Assign, and the url is pointing to this path: www.mysite.com/pages/Assing
How can I escape from pages controller and link to another controller action?

You are closing the parenthesis wrong :)
<?php $this->Html->link(__('Assign'), array('plugin' => 'full_calendar',
'controller' => 'events',
'action' => 'assign',
$events['Event']['id']
)
); ?>
The __() function should only correspond to the "Assign" string.
Beside that tiny mistake (always happens, so be sure to check for parenthesis mishaps before panicking), the way you're calling the function is ok and it should redirect you correctly.

Related

Zend Framework-Best way to hide Controller name

I am getting one problem in zend framework. I want to hide controller name in my zend framework url.
For Example https://example.com/index/about-us
I want to hide index controller from my url and i want url like
https://example.com/about-us
index is my default controller and about-us is my method
I have tried following code but it doesn't help
i have put this code in /application/Bootstrap.php
public function _initCustomRoute(){
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Zend_Controller_Router_Route(':action', array(
'module' => 'default',
'controller' => 'index',
'action' => 'index'
));
$router->addRoute('default-override', $route);
}
please help me to solve this problem.

Where can I get the route action in zend framework

This is my module.config.php
return [
'router' => [
'routes' => [
'home' => [
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => [
'route' => '/',
'defaults' => [
'controller' => 'rotation',
'action' => 'add',
],
],
],
And this is my add.phtml.
<?php
$form = $this->form;
$form->setAttribute('action',
$this->url('home/default', //your route name ...
array('controller'=>'rotation', 'action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('profilename'));
echo $this->form()->closeTag();
In line $this->url('home/default', //your route name ...
array('controller'=>'rotation', 'action' => 'add'))); I get a error. It doesn't display anything but when I erased that line it displays the textboxes.
My question is the url I put inside the code is correct or wrong? Thanks
For one thing to generate that route url with url helper you don't need pass in any parameters, because you've specified them in the defaults under options. Also since it's a literal I don't think you could even change the action (it's not variable for this type of route).
Sidenote: you don't need to pass in the whole route class name, because ZF2 already has it registered under Literal (case-insensitive), so you can shorten the value of type key.
$this->url('home') should return the result you're expecting.

Laravel 4 - Routes not resetting to root

I'm having an issue where when I go to a route with an href such as
example.com/user/foo
and then click on a link with a href such as
example.com/cart/bar
the URL sets to
example.com/user/cart/bar
and I get an error. The issue is the URL is not resetting to the root directory, but keeps the subdirectory('user') in the URL.
Here's a sample of a link to a user route:
<li>{{ Auth::user()->firstName }} {{ Auth::user()->lastName }}</li>
and the route:
Route::get('/user/{username}', array(
'before' => 'auth',
'as' => '/user/{username}',
'uses' => 'ProfileController#user'
));
the resulting call to the view:
return View::make('profile.user')
->with('user', $user);
at this point, the URL is:
example.com/user/john_smith
But then, let's say I want to view my shopping cart which has an href of:
<li>Cart</li>
and the route:
Route::get('store/cart', array(
'as' => 'get-cart',
'uses' => 'StoreController#getCart'
));
the resulting call to the view:
return View::make('store.cart')->with('products', Cart::contents());
the URL should be:
example.com/store/cart
but instead it's
example.com/user/store/cart
and I get a 'NotFoundHttpException'
You may use the url() helper function to generate an absolute url, for example:
<li>Cart</li>
Check the helper functions.

Zend framework 2, pagination routing issue

I have issue on zend pagination and routing in zf2 . I would like to display details of feedback item , and list of its sub items ( actions ) on the same page . My route code is given below
$routes['dashboard_inbox_actions'] = array(
'type' => 'segment',
'options' => array(
'route' => '/dashboard/inbox/detail[/:feedback[/actions/page/:page]]',
'constraints' => array(
'feedback' => '[0-9]+',
'page' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'Dashboard\Controller',
'controller' => 'inbox' ,
'action' => 'detail',
'feedback' => 0 ,
'page' => 1
),
),
);
I pass url like
/dashboard/inbox/detail/4
in listing page , for rendering the provided pages of subitems .
<?php echo $this->paginationControl($this->paginator, 'Sliding' ); ?>
which creates paging urls , with feedback id as 0 ( it my issue )
/dashboard/inbox/detail/0/actions/page/2
/dashboard/inbox/detail/0/actions/page/3
I manually paste url
/dashboard/inbox/detail/4/actions/page/2
Its shows page 2 as active item . My controller code works fine and gives me result , but still paginationControl creates url with feedback id 0.
You need to use the fourth parameter of the paginationControl view helper:
<?php
echo $this->paginationControl($this->paginator, 'Sliding',
'my_pagination_control', array('route' => 'paginator_route'));
?>
You can pass through parameters to the view partial, for example pass through your route name so you can generate yoru links using the correct route.
then inside your view partial you can use this in the url helper:
<?php echo $this->url($this->route, array('page' => $this->first), FALSE, TRUE) ?>
see: http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper
where you can see the url helper can use currently matches params:
url($name, $urlParams, $routeOptions, $reuseMatchedParams)
Setting $reuseMatchedParams to true will allow the use of the current matched params as default values.

cakePHP prevent user enter URL

I use router
Router::connect(
'/articles/:id/:slug',
array('controller' => 'articles', 'action' => 'view'),
array(
'pass' => array('id', 'slug'),
'id' => '[0-9]+'
)
);
BUT how to prevent user enter /articles/view/:id .I can make page /articles/view/:id become " NOT FOUND " ?
Router::connect(
'/articles/view/:id',
array('controller' => 'articles', 'action' => 'index'),
);
you are passing the slug, so just check that $this->params['slug'] isset and if it is not, redirect them to the home page.

Resources