Archive for category ‘CodeIgniter’

2009
20
Dec
Category: CodeIgniter, Work

I am working on some stuff for work (yes, on the weekend) that uses the Codeigniter Template Parser class to display content with pseudo variables. I have a pseudo variable parser that allows me to call up a certain function from a certain helper file. To do this I would do something similar to this:

{ns:gallery['foo']}

Where “df” is the name of the helper file (minus “_helper”) that gets loaded in if it hasn’t been already, “gallery” is the name of the function, and everything inside the brackets are values that get passed to the function.

I also thought about doing something more like HTML tags with pseudo variables. So the above example could be:

{ns:gallery name='foo'}

Similar concept but this way all of the attributes could be thrown into an object when it gets o the function so I can have as many or as few settings in it as I want instead of having to pass a certain number of arguments in a certain order. I would have to have default values for everything in case an attribute I needed wasn’t passed. Same idea as the way HTML tags work.

This is basically like creating my own pseudo HTML tags with { and } instead of < and >. So then I thought, why not make it a namespace tag? I would just have to replace the { and } with < and > and I get:

<ns:gallery name='foo' />

To do this I would so something similar to this post titled ‘Parsing Custom Tags With PHP‘.

There are advantages and disadvantages to all three. Right now I am leaning more toward the second or third options because if someone goes in after me and needs to edit the file, I think that makes more sense than the first way. Any way I go it just means extending the Codeigniter Template Parser class. Maybe I’ll do all three and release it to the Codeigniter community.

2009
20
Oct
Category: CodeIgniter, PHP

I was playing with CodeIgniter routing at work. I wanted to have a catch-all route but I needed to exclude a certain controller, or controllers, from that catch-all route. As an example, I wanted to have http://www.example.com/(ANYTHING) route to the “page” controller. http://www.example.com/policies/shipping would route to the “policies” controller and then to the “ship” method. From there the “page” controller would split up all of the segments.

I started out with this:

$route['policies/shipping'] = "policies/ship";
$route['(:any)'] = "page";

The “policies/ship” route would be caught by the “policies” controller and everything else would be caught by the “page” controller. Except the “page” controller was getting everything.

I needed to exclude certain controllers from the catch-all route. After a Google search, I came up with nothing. So I started working on it myself. Here is what I cam up with:

$route['policies/shipping'] = "policies/ship";
$route['^(?!policies|controllerA|controllerB)\S*'] = "page";

So far it seems to work perfectly. Hopefully this helps someone else out.