Yii Framework Forum: Separation the actions - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Separation the actions Rate Topic: ***** 1 Votes

#1 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 11 May 2010 - 11:57 AM

Hi!

I wanna create the admin panel as a module. It's rather simple. I have four parts in it: movies, photos, articles and news. Each of these parts has three actions: edit, add, delete ( and maybe move ). In url it must looks like:

Quote

movies/admin ( just for display list of movies in admin panel)
movies/edit/movie_id
movies/delete/movie_id

photos/admin
photos/edit/photo_id
photos/delete/photo_id

etc...


It's only for admin panel. But for diplaying on website we need some more action ( for example for the photos: view, size in, download ... ).

And all of this placed in one controller - in PhotosController. But I want to separate the admin part from users part, place ones in different controllers. All admin actions in AdminController, and others in appropriate controllers: PhotosController, MoviesController, etc.

But in this case I faced the problem. So we have action movieAction in AdminController, and we need at least three additional actions for this action: add, edit, move, list... And I dont know the right way to do this. I have only one idea is place the switch construction in each action:

public function movieAction() {
	switch ( $_GET['subaction'] ) {

		case 'add':
		..
		break;
		
		case 'edit':
		...
		break;
		
		...
		
	}
}


But it looks terrible :lol:

Is there any other ideas for realize it?
0

#2 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 11 May 2010 - 12:08 PM

You are complicating it.

Why not just have a controller say PhotosController and let it have it's own admin action i.e. PhotosController::actionAdmin() and do the same for other controllers.

If you must have your admin actions under one controller after that, consider using CController::forward();
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 12 May 2010 - 04:19 AM

You can create a module (read the doc because it not that simple) for admin.

In a module you will have other controllers for movies, photos, articles and news that will be accessed like admin/photos, admin/movies and so on.

So the controller in the main pool will be photos, with actions like photo/view, photo/download and so on.

In admin you will have actions like admin/photo/edit, admin/photo/delete.

Another nice stuff in doing modules, is that in the AdminModule.php you can put a security check, for forbit the entire module to anyone is not allowed. That avoid the problems that can happen if you forget to forbid a single action (is an additional check).

And, more and more interesting, I guess you can use the url-rewriting for access to admin module like admin.mysite.net
1

#4 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 13 May 2010 - 07:21 AM

zaccaria, thank you very much! I like this way and I'll try to realize it :)

P.S. А, так вы из Москвы :) Спасибо!
0

#5 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 13 May 2010 - 08:15 AM

@frantic: why don't use RBac for that? I mean one action for one thing do to and assign permissions to those actions.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users