Welcome Guest, Not a member yet? Register   Sign In
Website and admin structure
#1

[eluser]neosable[/eluser]
Probably this been posted tons of times but I couldn't find it. I am kind of familiar with CI already but I wonder how I manage to archive this:

HTML
/home
/products
/products/01
/contact

Admin page
/admin/products
/admin/products/add
/admin/products/edit/01
/admin/products/edit/01


is this possible without installing CI twice?
I am pretty sure this can be solved with .htacces and routes but I wonder if anybody has a hint for me on this

Thanks
#2

[eluser]underskor[/eluser]
This may help if you are interested in a solution that does not necessarily need routes and .htaccess.

Copy the default index.php that contains paths to system/ and application/ to your admin/ dir as well. Be sure to update the paths in admin/index.php.

Personally, I have:
Code:
/
  /app
    /site
    /admin
  /sys
  /html
    index.php ($app_folder points to app/site)
    /admin
      index.php ($app_folder points to app/admin)

This way, I can treat them as two seperate applications, which keeps me a bit more sane. Smile
#3

[eluser]Colin Williams[/eluser]
I think it's a bad approach, in some regards. I think controllers should focus on a single object or class of objects. So you would just have products/add, products/edit/it, etc (no admin folder).
#4

[eluser]neosable[/eluser]
[quote author="underskor" date="1232518460"]This may help if you are interested in a solution that does not necessarily need routes and .htaccess.

Copy the default index.php that contains paths to system/ and application/ to your admin/ dir as well. Be sure to update the paths in admin/index.php.

Personally, I have:
Code:
/
  /app
    /site
    /admin
  /sys
  /html
    index.php ($app_folder points to app/site)
    /admin
      index.php ($app_folder points to app/admin)

This way, I can treat them as two seperate applications, which keeps me a bit more sane. Smile[/quote]

Looks good , where do you have your statics files like css and images ?
#5

[eluser]underskor[/eluser]
@Colin;
Are you referring to seperating a web app into 2 halves? I can see there would be some issues in regards to duplicate code and having to maintain that duplicate code etc, but I think for relatively simple projects (eg. a portfolio, where the visitor does not interact with the site a great deal) it can simplify things a bit. Why do you think it would be a bad approach? Interested to hear your reply.

@Neosable;
Code:
..
  /html
    /imgs
    /css
    index.php
      /admin
        /imgs
        /css
        index.php

Also, it's a good idea to use absolute paths to refer to your assets.
#6

[eluser]Phil Sturgeon[/eluser]
Three methods.

1. Two applications

This is the method that underskor has demonstrated above.

Code:
/
  /app
    /site
    /admin
  /sys
  /html
    index.php ($app_folder points to app/site)
    /admin
      index.php ($app_folder points to app/admin)

This method does work, but is only really any good for big sites that have VERY different content for their front and back ends. You cannot directly use the same libraries, helpers, models, etc. I'm not a big fan of such frontend/backend separation as for most sites, admin is not a separate thing, just a set of functions for a particular object or entity.[/code]

2. Sub-directories

Just put all your controllers in a sub-directory of controllers.

Code:
/
  /application
    /controllers
      blog.php
      /admin
        blog.php
  /public_html
    index.php

3. Modules

Preferred: To keep my sites nice and modular, I put everything relating to a certain entity in a module using Matchbox. This means you can have your files laid out like so:

Code:
modules
—blog
——controller
———admin.php
——-blog.php
—-model
——-blog_model.php
—-view
——-entries.php

—comments
——controller
———admin.php
——-comments.php
—-model
——-comment_model.php
—-view
——-form.php

Then using some routing rules similar to below you can emulate the sub-directory URL's:

Code:
$route['admin/([a-z]+)/(:any)'] = "$1/admin/$2";
$route['admin/([a-z]+)'] = "$1/admin/index";
$route['admin'] = "admin";

This way you have your admin controllers next to their frontend controllers and you still have some nice URL's. :-)
#7

[eluser]neosable[/eluser]
Nice ideas thanks for all the comments :-)
#8

[eluser]Michael;[/eluser]
Greets all,

I just thought I would throw my set up into the mix here. It's a bit different, but it's rather organized and keeps everything clean and straight forward. As a lot of sites end up on a shared hosting plan, or just linux hosting in general, this does user a '/home/user/' path scheme ...

/system
/application
-> /controllers
-> -> /admin
-> -> -> blog.php
-> -> -> forum.php
-> -> blog.php
-> -> forum.php
/public_html
-> /assets
-> -> /css
-> -> /images
-> -> /js
-> /themes
-> -> /x-theme
-> -> /y-theme

This setup allows you to have a single application folder, thus only 1 index.php. No extra routing constraints or concerns. In fact, the only thing you have to remember is that www.example.com/admin/ will route to whatever your default controller is ... i.e. if blog.php is your default controller, then when you put www.example.com/admin/ into your browser it will default to the blog.php file in your admin folder.

Michael;
#9

[eluser]Phil Sturgeon[/eluser]
That is 2. Sub directories. Tongue

Good job for pointing out the default controller issue, its a pain that one.
#10

[eluser]Michael;[/eluser]
Oh boy ... it's 2am and yeah, I *completely* missed #2 in the post above. *sighs* Sleep, need sleep.

Michael;




Theme © iAndrew 2016 - Forum software by © MyBB