dqhgjay5753 2012-08-19 18:34
浏览 11
已采纳

Admin with Cake:创建新的应用程序,还是使用相同的?

I have build an e-commerce website with CakePHP Framework.

Now, i need to implement administration log-in, and orders/users management...

The big question is: Should i create a new App (a new CakePHP app folder), or use the existing one?

Using the same folder, would make me spend less time copying models, but, would considerably decrease 'security', because i would need to create methods for admin, and user...

Using separately framework, with almost the same models, would help me with the views... i would use another page template, and the log-in system would be different from the normal website.

So, what is the "best" solution for this case?

Thanks

  • 写回答

1条回答 默认 最新

  • douzhang5199 2012-08-19 18:47
    关注

    Build the admin in the same app. It doesn't decrease security. You can easily control which controller methods are accessible by admin users with Prefix Routing. You can also change the view layout based on the route prefix. If you need something more fine-grained, Cake supports Access Control Lists for complex permissions systems.

    In the end, your app will be much more maintainable if you are using a single set of models and controllers.

    Here's a little code snippet I use in app_controller.php. This is from an app built in CakePHP 1.2, so it may need to be updated slightly for newer versions. This assumes that any registered user has access to the admin URLs, but that could easily be changed:

    function beforeFilter(){
        if (isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
            if (!$this->Session->check('User')) {
                // save the url in the session so that you can redirect there after login
                $this->Session->write('lastPageVisited', $this->params['url']['url']);
                $this->redirect('/users/login/');
                exit();
            }
            // set the admin layout
            $this->layout = 'admin';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向