hi. First at all, try to create admin module, not controller: http://wiki.akelos.org/modules However, I've recently had simmilar problem. I had permission controller, and two models: permission and permission_scheme. Both of theme are scaffolded. Sollution: ` class Admin_PermissionController extends AdminController { var $models = 'permission,permission_scheme';
function listing(){
//standard, like in normal scaffold (you can use scaffold generator, then copy->paste)
}
//other functions
function listingScheme(){
//generate scaffold for permission_scheme, then copy->paste here
}
` then, all You need is edit a little bit views (for example form actions) I can click "Create permission" in permission/listing and add permission (render add() function) I can click "Create permission scheme" in permission/lisitng and add permission scheme (render addScheme() function) Sorry for my language errors - English isn't my native language.
Thank you for your help!
I did as you said (mostly.) I couldn't get a module to work right. I was able to make two separate models work. The problem really is that it doesn't utilize D.R.Y. (Don't Repeat Yourself). I end up with code that looks like this in my Admin Controller:
<?php
class AdminController extends ApplicationController
{
var $models = array('track', 'news');
function index()
{
$this->renderAction('control');
}
function control()
{
/** control.tpl has links to both editNews and editTrack and they work! **/
}
/** edit for news model **/
function editNews()
{
if(!empty($this->params['id'])){
if(empty($this->news->id) || $this->news->id != $this->params['id']){
$this->news =& $this->News->find($this->params['id']);
}
}else{
$this->redirectToAction('previewNews');
}
if(!empty($this->params['news'])){
$this->news->setAttributes($this->params['news']);
if($this->Request->isPost() && $this->news->save()){
$this->flash['notice'] = $this->t('News was successfully updated.');
$this->redirectTo(array('action' => 'showNews', 'id' => $this->news->getId()));
}
}
}
/** edit for track model **/
function editTrack()
{
if(!empty($this->params['id'])){
if(empty($this->track->id) || $this->track->id != $this->params['id']){
$this->track =& $this->Track->find($this->params['id']);
}
}else{
$this->redirectToAction('previewTrack');
}
if(!empty($this->params['track'])){
$this->track->setAttributes($this->params['track']);
if($this->Request->isPost() && $this->track->save()){
$this->flash['notice'] = $this->t('This Track was successfully updated.');
$this->redirectTo(array('action' => 'showTrack', 'id' => $this->track->getId()));
}
}
}
Sorry for the big code block.
editNews and editTrack both are essentially the same code, just different models. Shouldn't there be a way to have an action called edit that both editNews and editTrack refer to?
I am pretty new to Akelos and PHP in general. Perhaps I'm off base and should just be happy that the code I have works.
Input is so appreciated.
Thank you for your help!
I'm glad, that I can help someone - not only always ask for help ;)
I think that Your way of implemention isn't the best: Try to create admin module, where You can check, that user has permission, etc. Then, create two controllers - news and track. I mean, create something like that: admin_controller.php
`
class AdminController extends ApplicationController
{
public function __construct(){
$this->beforeFilter(array('_authenticate'=>array('except'=>array('authenticate'))));
}
function _authenticate(){
/*here put code,where You can check user permissions */
}
} `
then, create admin folder in app/controllers.
In this folder, create news_controller.php:
class Admin_NewsController extends AdminController
{
/*listing() edit() etc. */
}
the same for track.
then edit config/routes.php, and add as first:
$Map->connect('/admin/:controller/:action/:id', array('controller' => 'dashboard', 'action' => 'index', 'module' => 'admin'));
Sorry for my language errors - English isn't my native language.
Your English is fine!
I thought of making News and Track their own controllers, but it seemed like I'd be repeating the same code over and over...
You're probably right though. Copy and paste works great too.
Thanks for taking some time to help!
I thought of making News and Track their own controllers, but it seemed like I'd be repeating the same code over and over...
It's not the same code- it's logically different. You'll like it - with separate controlers, You can easly edit code.
You're probably right though. Copy and paste works great too.
copy paste? generators are much better ;)
Again kkrzyzak, thank you for your help!
I did make a couple new controllers and it all works great! I came across this post:
consolidating views: controller and table as variable?
This person is looking at it in a way similar to how I was.
Anyways, I'm up and running. These are thoughts for the next project. Cheers!
1 to 7 of 7