share models, libraries and helpers across both the front and backend - php

I created one application in codeigniter. But Now I want to move that to admin side. I have read 3 methods from http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter. Here I decided to use second one.
I that I created an admin folder in controller, admin folder in views,admin folder in css, and an admin folder in js to store the files like admin side controller, admin side views , admin css and admin js. I have set $route['admin']='application/admin';
And my question is:
When I access the file http:example.com/admin I am getting the page without js and css. How to solve that.
And one more question:
$this->load->views('add_user'). This statement changed to $this->load->views('admin/add_user')
Its difficult to change each and every page.

You can share models and libraries between applications by using CI 2 "Packages". Have a look in the Loader documentation to see how that works.

Related

Yii2 advanced, when to use the frontend folder and when the backend folder?

I recently started learning the yii2 framework for my internship in the advanced template. But I don't really get when you need to use the backend folder instead of the frontend folder. If someone could explain it, it would be appreciated.
Its verry easy.
Backend is your admin page, and frontend is your user page.
Let me explain.
You have models, what your backend use, and frontend use. If both have to use, you have to use common folder to share models with back and frontend.
When you make an app, in frontend you can create everything, what user need. Like registration, login, about us, etc.
In backend this will be your admin page. Like user search, modify rows, etc.
If any of your model need to user, and to admin, like user table, you have to use common folder. Then frontend, and backend will see this model. Be carefull with roules.
I hope i helped. :)
Frontend is typically what is presented to end user, the project itself. Backend is admin panel...
https://www.yiiframework.com/extension/yiisoft/yii2-app-advanced/doc/guide/2.0/en/structure-applications
Common - This directory used for common functionalities i.e. if we want to use same functionality in both backend and frontend in that case we can use this.
Frontend - This directory is used to create the website that is presented to end user.
Backend - This directory is used to implement the interface to manage that website (admin panel).

What is the structure of SocialEngine based on Zend

I want to know what the structure of Social Engine is. For example if I want to go to a page that the URL of that page is "http://example.com/stores/products", how can I find the controllers, models, views of?
When I go to direction application I see these:
languages
libraries
modules
plugins
settings
themes
widgets
and when I go into modules I see all modules added to the site including these:
Sitestore
Sitestorealbum
Sitestoreform
Sitestoreproduct
Siteverify
Sitevideo
and so on...
and when I go into Sitestore as an example, I see these:
Api
controllers
externals
Form
Model
Plugin
settings
View
views
widgets
But even now I don't know where to find the file I need related to the URL mentioned above.
Just tell me if you want to know what's inside each file.
Appreciation
You can get the controller and action name from manifest.php under modules/XYZ/settings/manifest.php.
Example, /stores/products
Go to modules/Sitestoreproduct/settings/manifest.php
Here you can see the slug_ of Store module and Products module.
For core modules, you will find the url structure in the /settings/manifest.php only, but in third party modules, SEAO and others they have extended the submodules by making it dynamic.
Hope it helps you to understand.

Codeigniter - Forgot to make an admin folder in controller and just created an admin.php controller

I created a controller called admin.php and placed it in the controllers folder. I was working on this "users" system where I was coding the things to edit, create, manage users. I made functions like users, edit_user, etc so when visited, it looked like http://localhost/admin/users, http://localhost/admin/edit_user
I am finally done that part.
Now, I am working on the site section of my panel where I will be able to edit the site. I just realized that I needed to create an 'admin' folder in the controllers folder so I could make a brand new users.php controller and place all my functions for managing users there.
I have no idea what to do. I don't want to put everything from the admin panel in a single admin.php file. I tried creating a new admin folder but I realized I have to change the url's to everything.

How to override a user profile view,, in our own plugin, in elgg

I have created a new plugin named 'adv' in my elgg site.
And in this plugin iam listing the users.Which using the view from other elgg plugin 'profile
ie the page profile/views/default/profile/listing.php.
Now i need to set a link in the existing view of each user.So i have to edit the profile plugin , mainly the page profile/views/default/profile/listing.php
But how can i do this, without modifying elggs default plugin 'profile'.
I have tried a method that i have copied the folder 'profile' from profile/views/default/profile and put it in adv/views/default/.But it donot working.]
Is any solution for adding new link to the user view with editing other plugin, only editing our own plugin example 'adv'.
You'll need to override the profile/listing view, but only when Elgg is rendering your plugin's pages, not to interfere with other plugins that might want to use the core profile/listing view.
My approach to this problem is the following:
Create a new directory that will hold the views that you want to override.
In your case, I'd create the "adv/views/mod" directory within your_site_root/mod.
Add the view you'd like to override into this directory.
Again, your case, copy the profile/views/default/profile/listing.php to the following location: adv/views/mod/default/profile/listing.php
Make your modifications to the newly created view.
You can now safely modify the adv/views/mod/default/profile/listing.php file to your liking
Tell Elgg to use the special view when your plugin is rendering the page. This means you'll have to call the set_view_location(..) method either from your page_handler function, or the php files that are referenced by your page_handler and usually prepare the data for the views (like index.php or read.php, but I don't know your plugin's file hierarchy)
So in your case you'd call set_view_location('profile/listing', $CONFIG->pluginspath . 'adv/views/mod/'); either from your page_handler or from one of the above files.
Make sure that $CONFIG is present and available by referencing it (global $CONFIG).
Please check if "Use view filepath cache (recommended)", is disabled in the site administration. Because elgg uses hard view cache. Or delete the view_cache file from the data directory. And also make user your plugin is below the "Profile" in the plugin list.

Best way to make Admin pages in CodeIgniter?

I'm working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I'm wondering what would be the better way to put these into an MVC structure.
Idea 1:
In each controller, have an admin function, and add all of the admin pages I would like into that function.
example URL: domain.com/articles/admin
Idea 2
Make a new admin controller, which would have to reference many different models, and put all of the admin pages in there.
example URL: domain.com/admin/articles
Which way would be better?
Edit for clarification: By admin functionality, I mean being able to do the basic CRUD actions on any object, and be able to display a list of all of said object.
Definitely a different controller at least!
I used to think that I could keep all my admin functions in a single controller, but as my programs grew, I realized that I needed multiple controllers in my administration section.
So, I created a folder inside my controllers folder with the name "admin" and put all my administrative controllers in there. So my folders would look something like:
application
controllers
front.php
welcome.php
admin
dashboard.php
useradmin.php
etc...
One problem this creates, however, is when you type http://mysite.com/admin in your browser, it returns a 404 page. So, go to your "application/config/routes.php" file and add a custom route:
$routes['admin'] = 'admin/dashboard/index';
I'll echo Justin in keeping it part of the individual controllers.
You should setup some kind of authorization system that the individual controllers can use to so who is logged in (username) and what access they have (admin/member/etc). Here's a SO thread on CodeIgniter Auth Classes.
The view would then conditionally show the appropriate links, and the controller would enforce the policy by checking the auth before passing any data to the model or rendering an edit view. On unauthorized access an error could be rendered, or simply render with the non-editing view.
This approach seems to make the most sense (at least to me) because all the functionality is stored in the individual controller. Keeping admin functions in a single admin controller means you'll have to manage two controllers (the admin, and the actual controller) every time you add somethign new (or remove something).
If you're concerned about putting auth checking in every controller, you could create a generic controller class with all the auth setup, then have your controllers extend it. In the end the individual controller auth check could be as simple as:
function edit()
{
if(!$this->auth()){
//display auth error, or forward to view page
}
}
Of course some kind of ACL implementation would make this better, but I don't believe CodeIgniter has an 'official' ACL.
It's a good idea to have an admin folder in the controllers folder wherein you can access your administration e.g. yoursite.com/admin/users.
All your administrative needs will be there and all methods will be protected by checking user privileges like so:
if ( ! $this->auth->logged_in(array('login', 'admin')))
{
$this->session->set_flashdata('message', 'You do not have access to view this page');
redirect('admin/users/login');
}
Then all controllers outside the 'admin' folder will - depending on your type of site - will only be for viewing, etc.. no administrative portions.
Idea 2 is better.
system/application/controllers/admin
You keep all your admin controllers here.
Here is an extensive guide to the pro's and con's of each method:
http://philsturgeon.co.uk/news/2009/07/Create-an-Admin-panel-with-CodeIgniter
Depending on what you mean by 'Admin' functionality...typically, this is thought of as an 'Edit' view.
And typically, you use the existing controller to serve the 'Edit' view allowing the authorized users to make the edits (in your case, Admin users only).
Looks like a personal choice, i love having everything centralized so the admin controller would be my bet.
That way i wouldn't have to open up 5 different controllers while modifying admin tasks.

Categories