Tuesday, August 31, 2010

CORE.PHP - Configure::write('Routing.prefixes', array('admin'));

Hi everybody,

This e-mail might look a little longer but I'm just trying to explain
my doubt clearly... Hope I can get to the end of it...

I've been using CakePHP for one week and since then I've been working
hard to get how things work. Definitely cake makes it easier as you
comprehend it's conventions, components, helpers, methods, etc.

The issue I'm sturggling at the moment has something to do with
Configure::write('Routing.prefixes', array('admin'));. In my app I
have a restricted area and since we start learning cake from the
database and models I've decided to start developing from that so the
data could be inserted in the db as the development flows.

My source of knowledge is cake cookbook, wich is very helpful, but
there's a lot of questions that it is unable to answer.

I figured out (and there's a good chance I might be wrong - hope you
guys are going to correct me if that happens)
that when we enable Configure::write('Routing.prefixes',
array('admin')) and use a
redirect(array('controller'=>'administrators','action'=>'admin_index','admin'=>true))
cake makes the URLs more friendly for a restricted area and it gives
no access for the methods from outside by putting a admin/ prefix.

In this case I'm must use a admin_ prefix in the methods so it could
work. Since cake don't give access to the methods from URL I thought
should have a index() method that checks the administrators login and
redirects the page.

Up to now I think everything is okay. The issue that I'm facing is
when trying to pass a params tho another method I have an error
because the other method get the params as a empty array.

Here we go:

I have a link on the page like this: administrators/edit/1

The functions with access is as follow and gets the params as 1. It is
responsible for checking the login and redirect to the accessible
method. The cookbook says that I can pass the action as an array with
the params.

function edit($id) {
// if user is logged in
if( $this->Session->check('Administrator') ) {
// redirect to restricted area
$this->redirect(array('controller'=>'administrators',array('action'
=> 'admin_edit', $id),'admin'=>true));
}
// or redirect to login page
else $this-
>redirect(array('controller'=>'administrators','action'=>'admin_login','admin'=>true));
}

The method bellow is the one that gets the empty array.
function admin_edit($id) {
// retrive data from the db
$result = $this->Administrator->retrieve_administrator_data($id);
// if it finds the user sets the data for the view
if ($result !== FALSE) {
$this->set('administrador_data', $result);
}
}

Can somebody help me out? I'm really not sure if this is the best
aproach for dealing with Configure::write('Routing.prefixes',
array('admin')); and I can't find wy the method is getting an empty
array.

Hope I'm not bothering with such an stupid question.

Thanks!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: