Welcome Guest, Not a member yet? Register   Sign In
Application Design (new to CI)
#1

[eluser]Richard Rowe[/eluser]
Hello All,

I'm new to CI, and to be completely honest quite new to PHP as well. Haven't worked with MVC either, but I think I'm getting the idea.

I'm trying to create a job listing web site using CI consisting of a Front-end (public access), User control panel (registered users access) and an Admin control panel (administrators access). I had planned to keep the admin views in /views/admin/, public in /views/public, etc. Because I have the view in a sub-folder in views, do I just $this->load->view('/admin/my-view'); or do I define the folder somewhere else?

Looking at this very generally, how would I go about setting up CodeIgnitor for this? What I was planning to do is have a controllers/public.php, controllers/admin.php and controllers/users.php but thought I may check here first for a more efficient method.

As I understand, all your data base queries need to be put in libraries or models?

I noticed a few scripts for CI that do the whole backend for you, I can't really use these as its for a school project. I can use snippets of code here and there though.

Any help / tips is appreciated. Been over the CI documentation briefly.

Thanks!
#2

[eluser]crumpet[/eluser]
[quote author="Richard Rowe" date="1229136796"]
do I just $this->load->view('/admin/my-view');
[/quote]
yes
[quote author="Richard Rowe" date="1229136796"]
Looking at this very generally, how would I go about setting up CodeIgnitor for this? What I was planning to do is have a controllers/public.php, controllers/admin.php and controllers/users.php but thought I may check here first for a more efficient method.
[/quote]
I would structure your application around the data not around the users
that would mean if its a job listings website
you have a controller called jobs
this controller has methods like create, edit, view
in these methods they figure out if its an admin or what
for a user control panel you might have a controller called panel
and then this has a function called view which shows a list of things they can do depending on their user type...
#3

[eluser]gstjohn[/eluser]
Although do-able how you are proposing, I don't think you are necessarily using controllers in the correct way. Controllers are meant to control the models.

Using your application example, you will likely have models (although not required by CI) such as 'Jobs_model', 'Employers_model', etc. You will then likely have controllers that are managing the interfacing between the website user and the models such as 'Jobs', 'Employers', etc.

This will allow your URLs to be referenced as:
http://www.somedomain.com/jobs/view/coder -> view jobs categorized as 'coder'
http://www.somedomain.com/employers/add -> add a new employer

If you want to have administrative sections, you can simply create a sub-folder named 'admin' within your controllers folder.

This will allow admins to access features with:
http://www.somedomain.com/admin/jobs/edit/1 -> Edit job listing #1
http://www.somedomain.com/admin/employer/suspend/2 -> Suspend employer #2

You can do the same for 'users'.

The views folder can really be laid out however you want, you will just need to make it whatever works best for you and then when you load the view, you just reference where you know it exists within the views folder.

Hope this helps!
#4

[eluser]Richard Rowe[/eluser]
Hey,

Thanks for the help. If I have a controller for jobs, employers (or accounts ??) what controller will I have for my main front-end. Just to list the jobs on homepage, etc etc..

I am still a little confused. But I'll get there :/. Do you by any chance know of any good video tutorials (or detailed written tutorials) that go over creation of a cms or something similar with a back-end as well as a front-end?

Quote:This will allow admins to access features with:
http://www.somedomain.com/admin/jobs/edit/1 -> Edit job listing #1
http://www.somedomain.com/admin/employer/suspend/2 -> Suspend employer #2

That'll mean I'll need another controller for jobs and employer in my admin folder? Won't it think /admin/ is the controller?

Cheers,
Richard
#5

[eluser]gstjohn[/eluser]
You jobs controller should be able to display all of the jobs on the homepage. It all depends on how you setup your route configuration. Sounds like you would want to set up the default controller to jobs and write your display code in the index() function.

I don't have any great resources or tutorials for the administrative portions. The way to think about it is that you have a whole different set of controllers within the 'controllers/admin' folder and you can redefine what each of those functions do for an admin vs. a user vs. a non-logged in visitor.

Example:
http://www.somedomain.com/users/add -> page for a user to signup
http://www.somedomain.com/admin/users/add -> page for an admin to setup a user acct (maybe has more options)

These are essentially two different controllers operating on the same model depending on access level.

Makes sense?

Note: The example crumpet suggests can also works too. I'll let him explain it though.
#6

[eluser]crumpet[/eluser]
If you dont want to do a whole new controller for admin you can simply put access features on each of your functions.

For example you have a function in jobs controller called create
when taht function runs the first thing you do is call a function in the model called can_create($userID)
this function checks the userID of the user and sees if they are allowed to create (sees if there an admin or whatever they need to create).
This is useful when you have your delete function which calls can_delete at hte beginning
can_delete can chck for two things 1. if the user created the job 2. if the user is an admin (admins can delete anything they want)

It is limiting if you want to do something complex or make a whole nother interface for the admin
but has basic functionality and is a lot less code.
#7

[eluser]Richard Rowe[/eluser]
Thanks for all the help! I'm starting to understand how things work.

Few questions though, what is the difference between a model and a library? Are models my functions that I plan on re-using over and over again, or is that the library?

Administration panel will be completely different interface.

Oh, and something else I just thought of. When I'm loading style sheets, javascript documents, etc... where do I put them? In views/js, views/css?

I'm still quite unsure how I get controllers in /admin/ folder to work correctly. For example if my URL was /admin/jobs/edit/5, jobs would be the controller in /admin/ folder. But wouldn't CI think admin is the controller, jobs is the function, and edit and 5 is just get data?

Thanks again! Learnt a lot already.

Richard
#8

[eluser]gstjohn[/eluser]
Sounds like you are getting the hang of it.

Models are PHP classes that are designed to work with information in your database. Think of models as objects, or often nouns (i.e. - offices, subscribers, states, etc.).

Libraries are also PHP classes that are found in 'system/libraries' and 'system/application/libraries' and are created for the purpose of extending the code. Often libraries are code bits that could be reusable from one project to another and so it's nice to have them modular.

Stylesheets, javascript, images, etc. all go in your webroot folder (likely 'public_html' or 'wwwroot'). This is on the same level as your index.php provided by CI. Don't put any of these files within your CI system folder. Although functional, it's just messy.

Lastly, regarding the admin folder for controllers, refer to:
http://ellislab.com/codeigniter/user-gui...subfolders
#9

[eluser]crumpet[/eluser]
[quote author="Richard Rowe" date="1229149906"]
Few questions though, what is the difference between a model and a library? Are models my functions that I plan on re-using over and over again, or is that the library?
[/quote]
Model is designed specifically to interact with a database. So for oyur jobs table you have a jobs model which as functions like get() and save()

libraries can be used for anything really. they basically let you add functionality. Most 'plguins' you find on this website are libraries . They should be application independant which means you can put them on any app you are doing.

[quote author="Richard Rowe" date="1229149906"]
Oh, and something else I just thought of. When I'm loading style sheets, javascript documents, etc... where do I put them? In views/js, views/css?
[/quote]
no these go outside of the application in css and js
/application
/views
/system
/css
/js

[quote author="Richard Rowe" date="1229149906"]
I'm still quite unsure how I get controllers in /admin/ folder to work correctly. For example if my URL was /admin/jobs/edit/5, jobs would be the controller in /admin/ folder. But wouldn't CI think admin is the controller, jobs is the function, and edit and 5 is just get data?
[/quote]
don't think so..
#10

[eluser]Richard Rowe[/eluser]
Thanks for the great advice, crumpet and gstjohn.

Thought of another problem. Lets say I want to have other pages on my site. About, RSS, FAQ, Contact Us, where should I be putting these? Would it be more efficient to have a Main controller (main.php) with all the pages on my site for example index for listing the jobs, about us, contact us, faq, etc.

EDIT: Probably sick of me, but if I don't have a single point of entry for admin panel (like how I was going to have an admin controller, public and users one... will that mean I'll have to check if a user is logged in on every single controller in the /admin/ folder? Is there a way to check if they're logged in, if they are let them in the controller if not send them off to login?

Cheers,
Richard




Theme © iAndrew 2016 - Forum software by © MyBB