Welcome Guest, Not a member yet? Register   Sign In
how to make use of more than one controller?
#1

[eluser]webdevguy32[/eluser]
okay, so I have one main controller, MAIN. And another one, so far, called STUDENT.

MAIN is used at the start of the program to help the login process. When an admin clicks on a menu to manage students, I think he should go to the admin controller. OR, better yet, when an admin logs in he should already, automatically be sent to the admin controller.

However, in my program since MAIN is the controlling controller, I can't seen to "break out" of MAIN to get to the other controllers. For ex., if the menu is "students/manage_students" -> that means the user is using the student controller and accessing the manage_student method. BUT, in my app, the user is sent to MAIN/student/manage_students.

Do I need o change the routing system or add a slash on the beginning of the controller? What am I doing wrong?

Thanks.
#2

[eluser]davidMC1982[/eluser]
If you're redirecting from a controller, use the redirect() method:

Code:
redirect('student/manage_students');

If you're linking inside a view:

Code:
<a href="&lt;?php echo base_url('student/manage_students'); ?&gt;">Manage Students </a>
#3

[eluser]webdevguy32[/eluser]
And if I am directing to a controller called MAIN in a subfolder of controllers called student:
/controllers/student/main/manage_students

then it would be something like:
Code:
redirect('/student/main/manage_students');

If you’re linking inside a view:
Code:
<a href="&lt;?php echo base_url('/student/main/manage_students'); ?&gt;">Manage Students </a>


Would that correct?
#4

[eluser]Tpojka[/eluser]
Yes, but you want to avoid forslash at start of uri segments in base_url in case your $config['base_url'] ending with '/'.
#5

[eluser]webdevguy32[/eluser]
okay. thanks.

I've read all the tutorials on the site and worked thru most of them. I've read the only book on safari I can find. I've viewed most of the MVC OOP PHP videos on youtube. They ALL show how to deal with a single controller very well, very simply.

Unfortunately, most projects of any size require more functionality than that. It will either be a HUGE main controller or it needs to be broken up into, at least, several controllers.

What would be MOST helpful to someone like me, years of PHP but now learning OOP MVC, is to see how application work in the real world, not just one class and here's how to instantiate the class. Helpful in the very beginning but it doesn't get you far.

If anyone has links to other places to learn this type thing, I would be very appreciative if you would share them. And I'm not talking about design patterns, I've read PHP design patterns and it's great and even give a little sample code, but, again, it does not bridge the gap between a single class and a single object to a real-world application.

Many thanks.
#6

[eluser]CroNiX[/eluser]
Look into libraries. They are classes that any controller can use.




Theme © iAndrew 2016 - Forum software by © MyBB