开发者

cakephp : admin routing issue : Parse error: syntax error, unexpected '/', expecting '(' [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I was trying to create an admin for my controller Posts, I used cake console option to create controller, I type Y for the question "Need admin routing ?", I entered Y and I got written my controller with admin functions, one of my admin function looks like this

function admin/controller_view($id = null) {
    if (!$id) {
        $this->Session->setFlash(__('Invalid post', true));
        $this->redirect(array('action' => 'index'));
    }
    $this->set('post', $this->开发者_StackOverflowPost->read(null, $id));
}

But when I execute I am getting the following error

Parse error: syntax error, unexpected '/', expecting '(' in C:\xampp\htdocs\cake\blog\app\controllers\posts_controller.php on line 61

I am using cakephp 1.3, What should I do to create an admin panel for this controller ?

Thaks a lot


The slash / isn't a valid character to be used in the function name eg admin/controller. That is why the error is there. You should remove the slash and re-name the function as per CakePHP's function naming convention.


what have you set up in core.php as the admin routing.. seems like you have 'admin/' it should just be 'admin'


Based on creating admin routing myself in cake, if you're trying to access the admin routing by going to mysite.com/admin/posts, then the function should have appeared as admin_view(), not admin/controller_view(). Unfortunately, I don't know what would have caused this, but correcting that should allow you to access the admin panel by going to mysite.com/admin/posts/view. If that doesn't work, can you post the contents of your routes.php?


Thomas, you probably misunderstood something in cake's docs. Here's how it works:

If you ask for /posts/view cake looks for PostsController::view().

If you have admin routing switched on (i.e. "prefix routing"), and ask for /admin/posts/view, cake will look for PostsController::admin_view().

Notice it's in the same controller!

You will also need an additional view file admin_view.ctp of course.

It can be a bit confusing at first, but don't worry, you'll get there! ;)


in your routes file inside config folder, you can use something like this

Router::connect('/admin', array('controller' => 'admins', 'action' => 'index'));

And your admin controller should be something like this

class AdminsController extends AppController 
{
    var $name = 'Admins';
    var $components = array('Email','Session','RequestHandler','Cookie');
    var $uses = array('Admins', 'Setting', 'Movie', 'User', 'Invitation', 'Purchase','Package');


    function admin_index() 
    {
        $this->layout = 'admin_default';
    }
}

now you can open your admin : mysite.com/admin/admins.

You don't have to use "/" while defining function. Hope this help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜