1
votes

I have created the zend framework structure like the following

application
  - configs
  - controllers
  - models
  - modules
     - admin
         - controllers
         - models
         - views
         ...
     - user
         - controllers
         - models
         - views
         ...
     - account
         - controllers
         - models
         - views
         ...
     - profile
         - controllers
         - models
         - views
         ...
  - views   
.....

I'm creating an application which have two different user roles as "user" and "admin". Both user and the admin should access the modules profile and only the admin have the access to the accounts module. Currently I'm facing an issue as follows

When i login as admin i get the following url in the address bar and i'm getting the admin menus and design (layout) perfectly as i expected localhost/public/admin/index

But when I click the edit profile link in the page, I lost the admin layout and the browser redirected to localhost/public/profile/edit URL. The same problem with the user module also.

What i exactly need is when i click the edit profile link, i should be able to access the page with the same layout(admin layout for admin) and the url should be something like http://localhost/public/admin/profile/edit

Is it possible to do with zend framework when i have the modules as i have given above? because I need to keep the system in a module basis and i dont want to redo the same code again and again. I checked in zend forums and i was unable to find the correct answer for what i'm asking.

Can Anyone kindly help me to solve this issue. Thanks in advance. Kind regards,

3

3 Answers

1
votes

Yes it is possible to create plugin_architechture in your system but as per my opinion your structure is not proper yet.

application
  - configs
  - controllers
  - models
  - modules
     - admin (Backend Modules)
         - user
             - controllers
             - models
             - views
             ...
         - account
             - controllers
             - models
             - views
             ...
         - profile
             - controllers
             - models
             - views
             ...
     - front (Frontend Modules)
         - user
                 - controllers
                 - models
                 - views
                 ...
             - account
                 - controllers
                 - models
                 - views
                 ...
             - profile
                 - controllers
                 - models
                 - views

You need to create two modules, 1) Backend 2) Frontend (Default).

You also need to hack some coding or either you should create your own autoload library that understand your new type of url. For example if i want to go in EDIT profile system of admin area then your url would be,

http://www.server.com/admin/profile_edit/edit/id=99

So in this case,

1) admin = module
2) profile = inner module of ADMIN 
3) edit = controller file inside profile module
4) edit = action function name in controller file (editAction())
5) id = parameter to pass 

To achieve this structure what you need to do is,

Create your own autoload library that extends files and classes of Zend library which are responsible to decode module/controller/action from url.

I personally created this structure and its worked. You should search in those folder files,

/library/zend/Controller/Action
/library/zend/Controller/Dispatcher

Let me know if you have confusion.

0
votes

The module will be accessed separately but, in the layout you can set the menus according to user/admin. You need to use the session variables a/c to the login user and you must pass them in the file where you render your profile page. i.e:

Pass the session variable to the index menu file, and show the menus accordingly. The layout issue will be solved then.

0
votes

First of all its hard to identify your problem, please specify it clearly so that someone would help you. What i have understood is "I lost the admin layout and the browser redirected to localhost/public/profile/edit URL."

  1. You lost your layout probably because you have changed it in current controller or disabled it. There is purely no question why you cannot use a single layout in multiple modules.
  2. And browser is redirected because you made it so.

Sorry if i was not on point but i was my best as understood your question.