• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A little help understanding the controller

#11
[eluser]wiredesignz[/eluser]
I use _remap() extensively with a base controller, _remap() is there for good reason and it is a very flexible feature of CI.

Routes and (xwero's favourite) Hooks are ok, but _remap() in a base controller can give you much finer control over your application.

EDIT: Try this base controller template to begin with, set up for a Blog application, but can be modified easily.
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Blog Controller
*/
class Blog_Controller extends Controller
{
    function Blog_Controller() {
        parent::Controller();
    }
    
    function _remap($action) {

    }
}
/* End of file MY_Controller.php */
/* Location: ./application/libraries/MY_Controller.php */

#12
[eluser]TheFuzzy0ne[/eluser]
I don't run and hide. It's more of a light jog which leaves me slightly camouflaged.

#13
[eluser]Dam1an[/eluser]
[quote author="TheFuzzy0ne" date="1240945143"]I don't run and hide. It's more of a light jog which leaves me slightly camouflaged.[/quote]

I was expecting you to say you LOLLERSKATE away Tongue

#14
[eluser]TheFuzzy0ne[/eluser]
I save the lollerskates for times when I need to move extremely fast.

#15
[eluser]xwero[/eluser]
wiredesignz MY_Controller is another thing that runs every time if you need it or not so all the bells in my head are ringing at the moment. But i understand you want to contain the module data.

_remap can do its work if there are no better options.

Colin changing the input class is the last thing i would think of to create userfriendly routes.

#16
[eluser]intoitdaily[/eluser]
wow thanks to everyone for the great support! It's obvious that this is quite a scalable framework and that there are many options. But I think I'm going to go with bargainph's suggestion and use routing. Afterall, it is exactly what I was looking for. When I get things running the way I want them, I'll repost my code and see if anyone else has some suggestions. Thanks again everybody!

#17
[eluser]intoitdaily[/eluser]
Holy Hell that was easy! It literally took me like 3 minutes to make it work! all I did was add
Code:
$route['blog/:num'] = 'blog/id';
to my routes.php file.
In my controllers I changed all the
Code:
$this->uri->segment(3)
to be
Code:
$this->uri->segment(2)
and in my views I changed all the anchors from
Code:
<?=anchor('blog/id/'. $row->id .'/', $row->title); ?>
to
Code:
<?=anchor('blog/'. $row->id .'/', $row->title); ?>

so simple! The only thing is in a large application, you have to stay on top of your routes if this is something you do often. It can get a little bit confusing if you forget to change a redirect link or something in a view or controller. Thanks again guys!

#18
[eluser]Dam1an[/eluser]
Well done for getting it sorted out Smile

[quote author="intoitdaily" date="1240951826"] The only thing is in a large application, you have to stay on top of your routes if this is something you do often. It can get a little bit confusing if you forget to change a redirect link or something in a view or controller.[/quote]

I normally seperate my routes into chunks, so all routes for posts go together, then all routes for users go together etc, it adds a bit of order...

It starts to get really messy when you play witht he ordering to give certain routes precedence over others


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.