Question

I've got a problem. I'm using zfcuser in my project, and now i want to create profile pages. I'have created the showAction() in UserController, but when i put the url to webbrowser, i will got 404.

public function showAction()
{
    $id = (int) $this->params()->fromRoute('id', 0);
    if (!$id) {
         return $this->redirect()->toRoute('zfcuser', array(
             'action' => 'register'
         ));
    }
    try {
    $user = $this->zfcUserAuthentication()->getIdentity()->getUser($id);
    }

    catch (\Exception $ex) {

         return $this->redirect()->toRoute('zfcuser', array(
             'action' => 'register'
         ));
     }

    return new ViewModel(array(
        'user' => $user));
}

I also created custom function to get User info all in one row. It looks like this:

public function getUser($id){
     $rowset = $this->tableGateway->select(array('user_id' => $id));
     $row = $rowset->current();
     return $row;
}

And it is in Entity/User.php

This is my showAction() in zfc UserController.php

I thought its wrong module.config, but its not working anyway. I changed my module.config to this:

'show' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/show[/][:id]',
                            'defaults' => array(
                                'controller' => 'zfcuser',
                                'action'     => 'show',
                            ),
                        ),
                    ),

My problem is, i can not even get to url to show this controller action. Where can be problem. I want to make simple user profile page.

Was it helpful?

Solution

The problem is in my opinion your route 'Literal'. A literal route can't have params.

You have to use Segment instead

But it's not the only problem i think. ZfcUser comes with a packaging, profile page already exist :

Take a look to this complete slideshare :

Zf2 Zfc-User

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top