phpyiiyii-extensionsyii-modules

Organize directories for applications with front-end and back-end in Yii


I am using technique to separate back end from front end in yii using following directory structure: wwwroot/

index.php
backend.php
assets/
images/
js/
protected/
    config/
        main.php
    components/
    controllers/
    models/
    views/
    runtime/
    backend/
        config/
            main.php
        components/
        controllers/
        models/
        views/
        runtime/

Ref: http://www.yiiframework.com/wiki/33/organize-directories-for-applications-with-front-end-and-back-end/

Problem is, I am not understanding how would we use Yii::app->createUrl() or Yii::app->createAbsoluteUrl() in back end for front end urls.

e.g Yii::app->createUrl('home/index') will echo "/backend/home/index" in back end controllers/views but i want it to echo like this /home/index which is for front end controller/view.

Please help me out with any solution.


Solution

  • I disagree with the technique described in that wiki document, you should create a module for your back end instead of trying to run two separate applications.

    This way your back end can share your models and components, but the controllers, views and any unique models are still kept separate.

    Then you can just go:

    $this->createUrl('backend/mycontroller',array('id'=>100));
    

    When you need to create a URL from a controller.