Welcome Guest, Not a member yet? Register   Sign In
Route using database information
#11

[eluser]Colin Williams[/eluser]
.. And the 'alias' table:

Code:
CREATE TABLE IF NOT EXISTS `alias` (
  `alias_id` int(11) unsigned NOT NULL auto_increment,
  `alias` varchar(254) NOT NULL,
  `path` varchar(254) NOT NULL,
  PRIMARY KEY  (`alias_id`),
  UNIQUE KEY `alias` (`alias`)
)
#12

[eluser]WanWizard[/eluser]
[quote author="Colin Williams" date="1226033910"]Also, going through your own front controller is seems to be a decent solution. I was going to go that route once...[/quote]
At the moment, this seams like the best solution.

I would only need to reuse the section of code that loads the controller and calls the method, basically the code in codeigniter.php between the pre_controller and post_controller hooks.

edit: just found out that this doesn't work. Once the controller is loaded, loading a second controller (which also extends the Controller class) causes a fatal error about an undefined object (in PHP4 at least).

Now trying to see if I can do something in the pre_controller hook...
#13

[eluser]Aken[/eluser]
I'm confused. This method seems like it's just creating a bunch of routes files. The user would then have to go in and create all the controllers and such for all of these, and such giving the user MORE work to do than normal.

I don't know what else you have planned, like if you intend on having the script create the controllers and views as well, but that sounds like a PITA.
#14

[eluser]WanWizard[/eluser]
[quote author="Colin Williams" date="1226035799"]Here's the class I got started on... maybe 50% of the way to being fully robust. It writes to config/db_routes.php, which you would then require or include from config/routes.php[/quote]
I'm definately parking this as the 'backup solution'. Thanx a million Colin!
#15

[eluser]WanWizard[/eluser]
[quote author="Aken" date="1226034121"]I have a similar solution set up to mine. For my site's news posts, I specify the local URL that I want. Then if the users goes to .com/news/new-post, it queries the DB for the URL "new-post".[/quote]
This is indeed what I mean with writing my own front controller. But it seams that instantiating a second Controller class within the first doesn't work, to that route is blocked at the moment. Not a problem if you can handle everything within that same controller, like you do.
#16

[eluser]Aken[/eluser]
Yeah after reading a little closer I figured it wouldn't work for you.

Why don't you have your server write all your custom routes to a text or PHP file, and just have your Routes.php file include it? While untested, seems like it would work.
#17

[eluser]WanWizard[/eluser]
[quote author="Aken" date="1226036925"]I'm confused. This method seems like it's just creating a bunch of routes files. The user would then have to go in and create all the controllers and such for all of these, and such giving the user MORE work to do than normal.[/quote]
It is. And it is meant to be. Your site is quite different from what I want to achieve. My content-tree is like a huge site-map of a website, stored in the database. The administrator can assign everything he wants to any entry of that side map.

For example: I have a controller /system/application/controllers/rbac/users.php. One admin could plug this into his tree at http://www.site1.com/admin/users, while a second admin could plug it in at http://www.site2.com/system/management/users.

So code is needed to check the URI segments against the tree in the database. If the path is found, the name of the object to load is returned (in this case controllers/users.php) which should then be loaded and called.

The core system would come with dozens of ready made controllers (from forums to blogs to albums to you name it), and the option to create static HTML pages which can be plugged into the tree as well. Besides that, my system is used as a framework for corporate sites as well, who will make their own controllers based on their requirements, which will simply slot into this system as installable modules.
#18

[eluser]Aken[/eluser]
Gotcha Smile

On a random note, I just tested including a PHP file with a few $routes set up inside Routes.php, and it worked fine. So if you'd rather not overwrite the entire standard Routes.php file, you can add in one line of code, then modify your own PHP file.

Also, one thing that might come in handy for your situation is XML. It was designed to have a nice hierarchical structure, so perhaps it can be implemented in your situation to take advantage of that. Just a thought.
#19

[eluser]WanWizard[/eluser]
I'm not to bothered with overwriting Routes.php (or another file that Routes would include), but I'm not to happy with apache needing write rights on a php file within the docroot. If the site ever gets hacked, it would be a great place to inject code, since it gets executed on every page load...

XML is a great idea though. Updates of the tree could trigger regeneration of the XML file (safer than a .php file), and I can parse it in Routes.php without requiring database access. Something for tommorow, I want to be in bed before the sun comes up again. ;)

Thanx for the assistance sofar!
#20

[eluser]Colin Williams[/eluser]
Aken, my class is meant to save aliases (routes) to useful URLs.

For instance, say someone saves a page and wants the path to be example.com/about-us/our-team. The controller is 'Page' and it has a method called 'view' that accepts a page id. So, somewhere in the process of saving this page we would create the alias:

Code:
// ...
$this->load->library('alias');
$this->alias->create($_POST['url'], 'page/view/'. $this->db->insert_id());
// ...

You would now have in db_routes.php:

Code:
$route['about-us/our-team'] = 'page/view/223';

It only creates one file, not many.




Theme © iAndrew 2016 - Forum software by © MyBB