I run with this default routing:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
Now i have set up user/index and user/login, by:
Class Controller_User extends Controller {
public function action_index()
{
#stuff
}
public function action_login(){
# stuff
}
Now i have another controller right now called class Controller_Restaurants. I can access this by restaurants/index, restaurants/view . I would like to access this as: user/restaurants/index, user/restaurants/view
I have this at the moment:
Class Controller_Restaurants extends Controller{
I tried with this:
Class Controller_User_Restaurans extends Controller{
But it does not work.. What have i missed?
Route::set('restaurants', 'user/restaurants(/<action>)')
->defaults(array(
'controller' => 'restaurants',
'action' => 'index',
));
I'd advise against using the default route, and build better, more meaningful specific routes.
Related
I have a subscriber to the event
'Shopware_Modules_Admin_SaveRegister_Successful'
and after certain actions, I want to perform a redirect in the end, but the $args object does not have a subject which means that I cannot call the $controller = $args->getSubject(); on it and perform a redirect.
Is there another way to perform a redirect inside of the callback function of this event? 'Shopware_Modules_Admin_SaveRegister_Successful' => 'onRegisterSuccessful'
public function onRegisterSuccessful($args){
$controller = $args->getSubject();
$controller->redirect(
array(
'controller' => 'profile',
'action' => 'verify',
'name' => $name
)
);
}
Try like this. Note that you need to exit() after the redirect, because after the event is fired, Shopware makes its own redirect to the customer dashboard.
public static function getSubscribedEvents()
{
return [
'Shopware_Modules_Admin_SaveRegister_Successful' => 'onregister'
];
}
public function onRegister(\Enlight_Event_EventArgs $args)
{
$url = Shopware()->Front()->Router()->assemble([
'controller' => 'profile',
'action' => 'verify'
]);
header('Location: ' . $url, true);
exit();
}
Your option would be to go a bit higher and register an controller's postDispatch event. There you can redirect.
I have route like this:
Route::set('forum/frontend', 'forum(/<controller>(/<action>(/<id>(/<id2>))))')
->defaults(array(
'controller' => 'thread',
'action' => 'list',
'directory' => 'frontend'
));
I also have controller: /modules/forum/classes/Controller/Frontend/Forum/Thread.php with name like this:
class Controller_Frontend_Forum_Thread extends Controller_Frontend {
public function action_add(){
}
}
But when I try to access url /forum/thread/add I get an error:
The requested URL forum/thread/add was not found on this server.
What is wrong?
I have to write a route in kohana for the following
$this->request->redirect("/" . input::post('custom_url'));
example if the custom_url = testpage
then it should be 'abc.com/testpage' and it should be redirected to a controller function example contoller/profile.
example if the custom_url = testpage1
then it should be 'abc.com/testpage1'
Route::set('event', '(event(/<url>))')
->defaults(array(
'controller' => 'event',
'action' => 'profile',
));
my url will be domainname/event/customname and it should redirect to event/profile. where event is controller and profile is action
The Model_Auth_User class in Kohana uses 'username', 'email','password' to create a new user
what if i want it to take only 'email', 'password' and also modify the validation to validate 'email_confirm' instead of 'password_confirm'
Finally i did it, All what I have to doe is to comment some lines which add the rules of validating user input
open C:\xampp\htdocs\kohana\modules\orm\classes\Model\Auth\User.php
and comment lines from 33:38 inclusive as following:
public function rules()
{
return array(
//as we don't have a username we don't need to validate it!
// 'username' => array(
// array('not_empty'),
// array('max_length', array(':value', 32)),
// array(array($this, 'unique'), array('username', ':value')),
// ),
'password' => array(
array('not_empty'),
),
'email' => array(
array('not_empty'),
array('email'),
array(array($this, 'unique'), array('email', ':value')),
),
);
}
You only keep the rules for validating what you need
Avoid changing of the system folder contents. Otherwise your changes will be lost after the next upgrade.
The more correct approach is to override the validation rules.
In file application/classes/Model/user.php:
<?php
class Model_User extends Model_Auth_User
{
public function rules()
{
$rules = parent::rules();
unset($rules['username']);
return $rules;
}
}
?>
may be duplicate but I don't get any proper answer or help
actually I want to do like:
my current URL is : http://mysite.com/MyController/view/page1
but I want something like :http://mysite.com/MyController/page1
means I want to hide action name from URL.
I have used
Router::connect('/:controller/:id',array('action' => 'view'),array('id' => '[0-9]+'));
but its not working for me
below one working fine but
Router::connect('/:controller/*', array('action' => 'view'),array('id' => '[0-9]+'));
it applies for all controller but I wanted to apply for specific controller
use
Router::connect('/MyController/:id', array('controller' => 'MyController','action' => 'view'),array('id' => '[0-9]+'));
You can use Cake's routing to get this to work.
Add the following to your app/Config/routes.php
Router::connect('/Controller/page1', '/Controller/view/page1');
But you will have to add a route for every 'page'.
You can use a wildcard route to match everything starting with /Controller/:
Router::connect('/Controller/*', '/Controller/view/');
Or, without touching routes:
class FooController extends AppController
public function index($stub) {
$data = $this->findByStub($stub);
if (!$data) {
die('page not found');
}
$this->set('data', $data);
}
}
}
Which allows you to have urls such as /foo/page1
(The routine looks for a Foo with a stub field matching 'page1')
This works, but you will loose the benefit of reverse routing which means you can make links like this: $this->Html->link(array('controller'=>'foo', 'action'=>'view', 'page1'); which cake will automagically rewrite to produce: /foo/page1
use this code
Router::connect('/:controller/*', array('action' => 'view'),array('id' => '[0-9]+'));
Try the following code for your controller, Here am using GroupsController as an example
You add this in your app\Config\routes.php
Router::connect('/groups/:slugParam', array('controller' => 'groups', 'action' => 'index'), array('slugParam' => '[a-zA-Z0-9]+'));
This should redirect all requests of the form
http://www.site.com/groups/* to http://www.site.com/groups/index
( * => whatever comes after the controller name )
So now i have to alter my default index function in GroupsController to reflect this change
<?php
App::uses('AppController', 'Controller');
class GroupsController extends AppController {
public function index($id = null) {
//pr($this->request->params); this where all data is intercepted...
if(isset($this->request->params['slugParam']) && !empty($this->request->params['slugParam'])) {
// i have a slug field in groups databsae and hence instead of id am using slug field to identify the post.
$data = $this->Group->findBySlug($this->request->params['slugParam']);
$this->set('group', $data);
$this->render('/groups/view');
}
}
}
?>
use this code
Router::connect('/MyController/:id', array('controller' => 'MyController','action' => 'view'),array('id' => '[0-9]+'));