A
A
Actor2013-12-27 13:18:13
Yii
Actor, 2013-12-27 13:18:13

How to split a mixed backend?

There is Yiinitializr, in the front there is an old admin panel based on Yii standard components, and partially rewritten in AngularJS. What is the best way to share?
The problem arose due to the fact that there are rules

// REST patterns
                '<controller:\w+>/<id:\d+>' 				=> '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' 	=> '<controller>/<action>',
                '<controller:\w+>/<action:\w+>'				=> '<controller>/<action>',


                array('<controller>/index', 	'pattern' => 'api/<controller:\w+>', 		'verb' => 'POST'),
                array('<controller>/index', 	'pattern' => 'api/<controller:\w+>', 		'verb' => 'POST'),
                array('<controller>/index', 	'pattern' => 'api/<controller:\w+>', 		    'verb' => 'GET'),
                array('<controller>/view', 		'pattern' => 'api/<controller:\w+>/<id:\d+>', 	'verb' => 'GET'),
                array('<controller>/update', 	'pattern' => 'api/<controller:\w+>/<id:\d+>',   'verb' => 'PUT'),
                array('<controller>/delete', 	'pattern' => 'api/<controller:\w+>/<id:\d+>',   'verb' => 'DELETE'),
                array('<controller>/create', 	'pattern' => 'api/<controller:\w+>',            'verb' => 'POST'),

                array('<controller>/<subaction>', 	'pattern' => 'api/<controller:\w+>/<id:\d+>/<subaction:\w+>',
                    'verb' => 'GET'),
                array('<controller>/<subaction>', 	'pattern' => 'api/<controller:\w+>/<id:\d+>/<subaction:\w+>',
                    'verb' => 'POST'),
                // default rules
                ''  => 'site/dashboard',

The top 3 rules override the API, and if swapped, the API rules will override those 3.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Makarov, 2013-12-27
@Actor

I personally would separate the api and the admin panel into separate modules simply.
As options, you can do this:
If the first three rules are used only for the admin panel, then I would simply add a suitable prefix to them:

...
'admin/<controller:\w+>/<id:\d+>'  => 'adminController/view',
'admin/<controller:\w+>/<action:\w+>/<id:\d+>' => 'adminController/<action>',
'admin/<controller:\w+>/<action:\w+>' => 'adminController/<action>'
...

Well, or if for more general options, I would create my own rule, in which I would check that the request is for api and would call the appropriate path.

D
DeD_PereGarbI4, 2014-12-30
@DeD_PereGarbI4

Look here habrahabr.ru/post/117457 , a good solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question