My problem is I'm developing a site with CodeIgniter, and the actual site and the admin are separated in different folders and using their own controllers, views, and model.
I would like to use only one database.php for both, and I can't really figure out how to point the admin database connection parameter to the site's database.php
Could someone give me a hint?
Thank you.
Justing adding my comment above as an answer here so that it helps other to know what worked to solve the problem -
If both the sites are at the same server - one of the quickest ways to achieve this is to setup all the values in database.php and in another just remove all the content and add this line -
include(/full/path/application/config/database.php) ;
Instead of using two CI structures you can use folders in controllers and views. For example:
application
controllers
admin
login.php
This will produce a url like: mysite.com/admin/login/
Just make sure to not create a Admin class in the root of controllers.
With this you will have just one database configuration for both admin controllers and normal controllers.
Related
I want to build a react application where there will be two types of UI, one for admin and other for user. All the files included in header and footer will be separate. how can I achieve this?
Approach 1
Creating two separate application for admin and user like
example.com for user and admin.example.com
So that I can include all the css and js files of respective design in index.html
Approach 2
Integrating in one application where url will be example.com for user and example.com/admin for admin.
but then my question is where will the asset file will in included for both user and admin where the respective template will be created.
Please help and pardon me if the question framing is not correct.
The second approach looks better to me.
Where to include assets and where to create the template?
Have all the Components (admin + user components)in the Components folder, and in App.js, while defining the routing, provide components to routes accordingly. For example:
for path="/", it should provide component <UserHome/>
for path="/admin/", it should provide <AdminHome/>
Hope that answers your question.
Both these are equally good.
Would recommend method 2 if there is any common data or function between them
I am trying to move from CodeIgniter to CakePHP and can't figure out the best way to implement an admin panel. In CI I would create two different applications, one for the frontend and one for the admin panel.
After Googling around, I have found three ways to implement admin panel in CakePHP:
Routing - I don't want to use this as I want by Controllers/Models to be separate for frontend and admin panel
Plugin
Two separate apps
Should I use plugin to implement admin panel or should I have separate apps? Any benefits of one over the other?
I normally develop the admin/backend as a plugin. This keeps your backend/admin controllers/views/models separated from the frontend and you don't have to jump through hoops to have separate stylesheets, layouts etc.
Another advantage is that both front- and backend are still part of the same application, so if desired, you can share logic/components, for example you'll be able to put helpers that are usable both for front- and backend in another plugin (e.g. plugins/Shared or plugins/Handytexttools) and use those both wherever you want
As a rule of thumb; put components that may be reuseable for other projects in a separate plugin, this way you can just add those plugins to other projects without problems. Keep your plugins simple; it's no problem to create a plugin containing just one or two helpers or models and a few files of JavaScript. This will make it easier to 'cherry pick' the plugins that you need for a project. Once Cake has 'cached' the file-locations of all classes in your plugins, the overhead of separate plugins should be minimal.
Coming back to the 'admin' plugin. Try to only include code specific for this project in your admin plugin and reusable parts in another one (e.g. Generic stylesheets and layouts for admin-panels). You'll be able to start a admin-plugin for your next project with minimal coding
Good luck with your project and enjoy CakePHP
If you want to keep your controllers and models separate - I'd go with a separate app, although you'll end up with a bunch of duplicate code between the apps (maintenance headache waiting to happen).
My choice would be admin routing and an admin theme.
Enable admin routing in /app/Config/core.php
In AppController beforeFilter():
$this->theme = isset($this->params['admin']) ? "Admin" : "Site";
Move all your site views and assets into /app/View/Themed/Site/
Create your admin themes in /app/View/Themed/Admin
Old and refers to CakePHP 1.3, but still is a question you should check: CakePHP admin panel
The Cake way is routing. I'd go with a plugin like CakeDC Users that makes things easier.
You could use admin-routing. Check out:
http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing
Another solution -which I find really easy to implement- is like this:
In your AppController:
public function beforeFilter(){
$this->set('current_user', $this->Auth->user());
}
This makes the $current_user available in your app.
Then in your view-files, you can check:
<?php if ($current_user['role'] == 'admin'){/*place code for admin users to see here*/} ?>
<?php if ($current_user){/*place code for logged-in users to see here*/} ?>
I know this is an old thread. But would like to ask if anyone had trouble implementing the admin panel as a plugin. Particularly duplication of code.
For example you're implementing an e-commerce site. You have an OrderController both in the main and admin plugin. Don't you think it's kinda hard to maintain the logic in two places?
How about just using one main controller. It's serves two purpose. One as an API then the controller for your Admin webapp.
Your public side would then basically communicate via API to fetch data.
Do you think it's a good idea?
You can use admin views like admin_index.ctp just change this
//Configure::write('Routing.admin', 'admin');
to
Configure::write('Routing.admin', 'admin');
in core.php and in the controller add admin_index() function
In CakePHP, is there a way to set admin routing on an URL like this:
...com/admin/articles/
to go to:
View/Admin/Articles/index.ctp
instead of:
View/Articles/admin_index.ctp
My thought is, it would be nice to keep my admin files more separate from my front-end files, since I'd like to re-use my admin over many projects. If this can be done, are their negative side-effects I haven't thought of?
Just set Controller::$viewPath to whatever you need. In your AppController::beforeRender() set $this->viewPath = 'Admin/' . $this->name;
why don't you create a separate app for your admin? Or create a plugin with it? With that you could reuse it in all your projects.
I have successfully created a static website using cakephp to create the static html files using the console.
However, what I want to do now is have a console script that can create multiple websites from the same shared data, with each website using data that is unique to it, but sharing the db as a source.
So, how do I set up the app folder in relation to each website? Do I need a separate installation of cakephp for each site? Or can I have a shared App folder in cgi-bin or something like that?
Thanks
You can share the CakePHP core between multiple apps, however you will need a separate 'app' folder for each website (with the appropriate structure). See this question for more details. Essentially you will need to modify the index.php file in each app/webroot folder to point to the CakePHP core. I use this technique and it's much easier to maintain with only one core as opposed to a whole separate installation of Cake for each site.
I have problem with session in cakephp.I have one file chat.php that is in webroot folder but when I run that file with ajax I could not find session which is created from chat.ctp file.
so anyone has idea how to get session in third party file in cakePHP.
can I write session any .ctp file ?
Thanks.please help me.
Yes, it's totally possible.
In APP/config/core.php, find the "Session.cookie" config value:
Configure::write('Session.cookie', 'CAKEPHP');
Then, in your external file, just set the same session name when you start your session:
session_name('CAKEPHP');
session_start();
print_r($_SESSION);
I have heard that this is a spotty thing but for me, the solution above has worked in two projects so far.
I'm assuming you're using the Session component to write the session variable and then trying to read it from a regular 'ol php file outside of cake's scope using the $_SESSION variable.
As you have figure out, this is not guaranteed to work properly. The best way to handle this would be to integrate your chat.php file into cake, using a controller, action and view.
If this for some strange reason isn't possible, you would need to import all the files responsible for setting up cake and instantiate the session component and use that to read from your session. I'd strongly recommend going with way #1.
I don't think it's a good idea to use the third party session in CakePHP since Cake has already done that very well.And I believe the best place to make some sessions is controller,not view.See Session in Cakephp's cookbook and Ajax helper of Cake.Probably they would help.