Welcome Guest, Not a member yet? Register   Sign In
Best practices?
#1

[eluser]sheldonnbbaker[/eluser]
So I'm porting over an application I made a few months ago from my own framework to CI - so I'm probably gonna have quite a few questions along the way regarding best practices and how to do certain things, so here's the first one I guess:

- where is a good place to have a redirect script for misspelled URLs? e.g, if a user goes to mysite.com/book_for_sale/ instead of mysite.com/book_for_sale/id_number_554542423, I want to redirect them to mysite.com/all_books_for_sale.

Should I make a hook here - 'cause doing a redirect in the controller is kind of 'late', is it not?

Thanks Smile
#2

[eluser]xzela[/eluser]
url redirect should probably be done in the .htaccess file with mod_rewrite. that's assuming you're using Apache.

search for 'apache mod_rewrite' in google for more details and examples.
#3

[eluser]sheldonnbbaker[/eluser]
Hmm - okay. I am using CI's routing right now and I'd like to use that rather than mod_rewrite, but maybe a combination of both would work fine.

Thanks Smile
#4

[eluser]sheldonnbbaker[/eluser]
Alrighty - another question:

Where should I store all my 'common' functions that are used primarily for appending html to things?

E.g., I usually like to wrap my content in rounded-corner boxes, so the HTML markup includes a few divs before the content, and a couple after the content.

I of course want to have it in one file (I'm assuming that I should use a view) - but how could I do it so that in my main content views, I can just go like this:

Code:
<?= $top_html_portion_of_type_6_box; ?>

<p>My content here.</p>

&lt;?= $bottom_html_portion_of_type_6_box; ?&gt;
#5

[eluser]jalalski[/eluser]
You have a lot of options, but the most applicable would be to extend the HTML Helper to include the functions that you need, so then your view could be:
Code:
&lt;?php echo box_top(6); ?&gt;

<p>some content here</p>

&lt;?php echo box_bottom(6); ?&gt;

Other options would be to create your own helper module or pack it in a library module...
#6

[eluser]Iverson[/eluser]
[quote author="sheldonnbbaker" date="1233365909"]So I'm porting over an application I made a few months ago from my own framework to CI - so I'm probably gonna have quite a few questions along the way regarding best practices and how to do certain things, so here's the first one I guess:

- where is a good place to have a redirect script for misspelled URLs? e.g, if a user goes to mysite.com/book_for_sale/ instead of mysite.com/book_for_sale/id_number_554542423, I want to redirect them to mysite.com/all_books_for_sale.

Should I make a hook here - 'cause doing a redirect in the controller is kind of 'late', is it not?

Thanks Smile[/quote]

All you need to do is at the beginning of whatever controller function handles "mysite.com/book_for_sale/", check first to see if your book exists in your db by looking for segment 2, which is the id number. If it doesn't, just use the redirect function in your controller. Redirect() is in the URL helper.


mod_rewrite should be your last option. There are so many options in PHP and Codeigniter. I'm actually very surprised that the first suggestion to a n00b in our CI forum is to start mucking with Apache :coolmad:




Theme © iAndrew 2016 - Forum software by © MyBB