generate links from backend to frontend

Sorry for my English

The site I built the structure described here http://www.yiiframework.com/wiki/33/

Everything works fine and I am pleased by the separation. But there was one problem. Needed to create a link from the admin on the client side. The problem in the first place is that urlManager inserts a link instead of the required admin.php index.php. Second transformation rules are in url to the config file frontend.

I implemented it this way.




class FrontendUrlManager extends CUrlManager {


    private $_baseUrl;


    public function __construct() {

        $frontend=include(Yii::getPathOfAlias('frontend.config.main').'.php');


        $config=$frontend['components']['urlManager'];

        unset($config['class']);

        foreach($config as $key=>$value)

                        $this->$key=$value;

    }


        public function getBaseUrl()

        {

                if($this->_baseUrl!==null)

                        return $this->_baseUrl;

                else

                {

                        if($this->showScriptName)

                                $this->_baseUrl=Yii::app()->getRequest()->getBaseUrl().'/index.php';

                        else

                                $this->_baseUrl=Yii::app()->getRequest()->getBaseUrl();

                        return $this->_baseUrl;

                }

        }


}



Using now so

Yii::app()->frontendUrlManager->createUrl(‘site/index’);

Solution until the suit but decided to show it here. Perhaps there is a much better option.

You current implementation is fine :)

How is supposed is the implementation?

I created that as component and saved in /protected/components/FrontendUrlMananger.php

Then, in main/config.php:

‘import’=>array(

    'application.components.*',

),

If I write Yii::app()->frontendUrlManager->createUrl(‘site/index’) I get: Property “CWebApplication”.“frontendUrlManager” is not defined

What’s wrong?

I only needed to set this in config/back.php:


        'components'=>array(


            'FrontendUrlManager'=>array(

                'class'=>'application.components.FrontendUrlManager',

            ),