How Can I Handle Admin Module Controller, Models To Public?

As per this thread, http://www.yiiframework.com/forum/index.php/topic/47220-how-do-i-separate-public-guest-and-admin-pages-in-my-diocese-website/

I have choosen module based separation for admin & public pages. I have created module for admin to do all CRUD.

Now, How can I handle for public? Like some functions to be displayed for public from admin CRUD? When I try to access public … it shows "admin" as the path name?

How can I hide this ? Do i need to create separate controllers/models for public in the "protected" folder?

How you guys are handling this?

my folder structure is like this,




index.php

        assets/

        protected/

                config/

                        main.php

                components/

                controllers/

                models/

                views/

		modules/

			admin

				 components/

                		 controllers/

                		 models/

                		 views/

        			AdminModule.php

Hi

=> First you want to create the default layout on protected/view folder


 1)view/layout/main.php

    2)view/index/index.php

=> create the default controller protected/controller/IndexController.php

so when site is running you want to call a layout on protectd/view/layouts/main.php

after user login on frontend you want to call layout on every module (frontend module laayouts/view/main.php)

=> you want to create all model on protected/models folder not in separate

=> Create the controller on separate and default controller is IndexController on front end module. and defult action is Index so every controller call a default action is Index action. and in Admin module you can set a defult action is Admin.

=> so On everu module you can set the default view on index on defult file is view/index/index.php


index.php

        assets/

        protected/

                config/

                        main.php

                components/

                controllers/

                models/

                    -All model and base model


                views/


                     

                     layouts/main.php

                     layouts/index.php

                modules/

                        admin

                                 components/

                                    --AdminCoreController.php 

                                 controllers/

                                     --IndexController extend AdminCoreContller

                                 models/

                                 views/

                                    /layouts/admin.php

                                    /index/index.php

                                AdminModule.php

                         FrontEnd

                                 components/

                                    -FrontCoreController.php 

                                 controllers/

                                      --IndexController extend FrontCoreController

                                 models/

                                 views/

                                    /layouts/main.php

                                    /index/index.php

                                FrontModule.php




Then after you want to create the CoreContrller on module/components folder and set the defaut layout.

And finally you want to set the url structure on confing/main.php file


'urlManager' => array(

            'urlFormat' => 'path',

            //'showScriptName'=>false,

            'rules' => array(

              //set a admin url

                'admin/' => 'admin/index/index',

                'admin/login' => 'admin/index/login',

                'admin/logout' => 'admin/index/logout',

                'admin/<controller:\w+>/<action:\w+>' => 'admin/<controller>/<action>',

               


               // set a fontend url

            

                'user/'		        =>'user/index/index',

                'user/login'		=>'user/index/login',

                'user/logout'		=>'user/index/logout',

                'user/<controller:\w+>/<action:\w+>'=>'user/<controller>/<action>',


             //set a controller and action 

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

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

              '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

            ),

        ),



  1. create the default layout defind on componets folder

  class AdminCoreController extends GxController

{

	public $layout 		= 'admin';

	public $accessRule  = '';

	public $userType 	= 'admin';

	public $defaultAction = 'admin';

        

      //some other function 

}






<?php

/**

 * Controller is the customized base controller class.

 * All controller classes for this application should extend from this base class.

 */

class FrontCoreController extends GxController

{

	public $layout='main';


	public function init()

	{

		parent::init();

	}

	

}

so in admin module call a defult layout is admin.php and front end module call a defult layout is main.php.

So in your site load


1)localhost/test/index.php

after user login


2)localhost/test/index.php/front/index

3)admin you can write a


localhos/test/admin

I hope it’s may be helpful.

Thanks, Ankit Modi I will go through and get back

Also you can see this wiki

One question,

The layout part is ok, for admin and public… but how can I show some function like …

There is CRUD operations for Manage Priests (Add/edit/delete/view more) … but for public , i want to display customized priests details with only view more? how to achive this ?

In gii you can set the path on module

like if i want to create the model using gii so all model are generated on protected/models

and more important if you want to create the CRUD you want set the module path on creation time see this image

4707

Screenshot from 2013-09-20 12:00:02.png

in this image you can see the path

modules/admin/controllers/BannerManagementController.php so it;s creation on admin module folder and create the conterller and views file on admin module.

Thanks, It looks OK . I have done like that.

For public view, So, I need to create Models, Controllers and do the process?

protected/models

protected/controllers

Yes is it correct for public view you can create the modles,controller and view on protected folder and particaular user view menans user login then call on frontend controller and views.

But make sure all models are in your modle folder not in seprate folder.