Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:42:14+00:00 2026-06-04T17:42:14+00:00

I have a method in my Users Controller called view , which should display

  • 0

I have a method in my Users Controller called view, which should display a specified (by URL) user:

public function view($username = null) {
    $this->User->username = $username;

    if (!$this->User->exists()) {
        throw new NotFoundException('Няма такъв потребител!');
    }

    if (!$username) {
        $this->Session->setFlash('Няма такъв потребител!');
        $this->redirect(array('action' => 'index'));
    }
    $this->set('user', $this->User->read());
}

And in the route config:

    Router::connect('/:username',   array('controller' => 'users', 'action'=> 'view'), array('username' => '^([a-z0-9])+$'));

But when I try: www.example.com/Username it returns a fatal error: Missing controller.

I tried also this:

Router::connect('/users/:username', array('controller' => 'users', 'action'=> 'view'), array('pass' => array('username'), 'username' => '^([a-z0-9])+$'));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:42:16+00:00Added an answer on June 4, 2026 at 5:42 pm

    Unfortunately for this sort of setup using /:username is too simple, it will pretty much override every single other route. To do this effectively ( + the proper CakePHP way) you need to setup a custom route, here is mine which pretty much achieves the same thing. Just replace “product” with “user” for most cases, read through it though, to make sure you understand what’s going on..

    Look at my routes config as well if you still can’t work it out.

    If you want to route /user/dunhamzz to a profile you would set it up like this:

    Router::connect('/user/:username',
        array('controller' => 'users', 'action' => 'view'),
        array('pass' => array('username')
    );
    

    Then your view action simply gets the username as the first argument:

    public function view($username) {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller which has a method called history class UsersController < ApplicationController
I have a view controller which contains a field for user to enter date
I have a Rails controller action to test. In that action, a method User.can?
I have a controller user with a method login For some reason, when I
I have the following code in my controller action method: if (User.Identity.IsAuthenticated) { //
I have a method in a webservice that has parameter with which users can
I have a method which uses an index located in a specific directory. public
I have a controller called EmailController , which is (you guessed it) responsible for
On a Rails 3.1 app, I have a method called user_logged_in? from Devise, which
I have a modal view which gets the user to select some data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.