MVC Incorporating an action into the most appropriate correct controller

I'm just wondering which approach is best for deciding where to create an action / presentation in certain situations.

If User hasMany Video

Where is the best place to create an action / view for showing a user's video?

So, on the My Videos page of the Users page, you

  • just create an action and view users / my_videos .
  • create video / my _videos action and view.
  • or, most likely, you will already have a controller / action video / index in which there is a search function. Just use this pass in your user id.

Any thoughts / advice were very valuable.

thank

Leo

+3
source share
5 answers

One of the possible options is as follows:

Since videos probably have much more code around them than a simple user who has videos, the action of the video list should be in VideoController.

In past projects, I (in CakePHP 1.3) use prefix routing to solve some of these problems.

In config / core.php, make sure you enable routing.prefixes to enable the prefix 'user'.

<?php
    ... in routes.php ...
    Routing.prefixes = array( 'user' );
?>

In the video controller, perform the action with the following signature:

<?php
    ...
    public function user_index( $userID = null ){
        ...
    }
?>

and in the views where you are linking to the list of user videos, the html :: link call should look something like this:

<?php
    ...
    echo $this->Html->link( 'User\ Videos', array(
        'controller' => 'videos',
        'action' => 'index',
        'prefix' => 'user',
        $this->Session->read( 'Auth.User.id' )
    ));
?>

, , Auth . .

: ) , b) - site.com/user/videos/index/419

Slug ( , - db slug) http://42pixels.com/blog/slugs-ugly-bugs-pretty-urls)

, URL-: site.com/user/videos/index/eben-roux

app/config/routes.php /index/, SEO : site.com/user/videos/eben-roux

http://book.cakephp.org/view/945/Routes-Configuration

+3

:

1)

2)

- , , ?

MVC , , , : , , , ? , , vids? , .

- , , , , .

0

.

, , , .

public function index($id = null){
   $this->paginate = array( 'conditions'=> array('Video.user_id' => $id));
   $this->set('videos', $this->paginate());

}
0

, , .

, - User Video- .

, - UserDashboard ( - , ), Dunhamzzz . " ". //.

UserDashboard / ( IVideoRepository IVideoQuery).

, - , . , . / .

.

0

, " - ", , , , / .

, - - , ( , , ..).

, , - URL-, . URL- .

0

All Articles