Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
|
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2009, 10:35 PM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying Product Categories - the page links

Hello Thomas Myer,

Thanks a lot for this great book. I'm following it page by page. :)

From: 89 to 92.

I have no idea what to do any more:

On my view v_header,I'm getting the links with url and category name.:

Code:
<?php
echo "<ul>";
foreach ($listacategorias as $categoria)
{
   echo "<li>";
   echo anchor("c_categoria/$categoria->id_cat",$categoria->nome_cat);
   echo "</li>";
}
echo "</ul>";
This works. Nice.
It will give me something like:
http://site.com/c_categoria/1
http://site.com/c_categoria/2
http://site.com/c_categoria/3

The issue is that, when I click on those links I get a 404 error.

Please help me out:

In my controller c_categoria, I'm having the following:
Code:
function cat($id)
{
    $cat = $this->M_Categoria->getCategoria($id);
                
    $data['titulo'] = "As nossas soluções para ".$cat->nome_cat;
    $data['listacategorias'] = $this->M_Categoria->getCategoriasPrincipais();
        
    $data['categoria'] = $cat;
        
    //o homepage_tpl should get this value:    
    $data['main'] = 'v_categoria';
        
        
    $this->load->vars($data);
    $this->load->view('homepage_tpl');
        
}


My template homepage_tpl, grab the array key main as $main, here:
Code:
<div id="container">
        
<?php $this->load->view('v_header'); ?>;
            
<?php $this->load->view($main); ?>;
    
<?php $this->load->view('v_footer'); ?>;
    
</div>




Can anyone help me out on debugging this, and understand why I'm I getting a 404 ?

:(
Márcio


Ps- on the controller I have also tried like this:
$cat = $this->M_Categoria->getCategoria($this->uri->segment(3));

No luck. Same 404 as ever.




ps 2 -
It's a shame that Claudia only wants one subcategory and then products. I do have a similar situation but, my Claudia wants multi categories, and I'm struggling about how can I do that.

If it's possible, could you or anyone else, grasp the logic behind the process of building a product category with n categories instead?
 
Old August 30th, 2009, 09:51 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok.

Solved. I was not passing an id on the anchor argument.
I missed one segment on anchor URI build.


Still, I do believe Claudia would be much more happier with a n level category solution. At lest, if she want, (we never know) on the future, have another sub sub sub category, she could create one.


Regards,
Márcio
 
Old August 30th, 2009, 10:34 AM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default Interesting thought

Well, I dunno if what you propose is actually doable, where you pass in an ID straight to the controller without even calling a function. In fact, I think it's pretty much not doable.

However...what you could do is set up a series of aliases that let you do that--for example, in your routes file you could work it such that any category/1, category/2, category/n link actually gets processed by category/view/n
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
 
Old August 30th, 2009, 11:58 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Nice. I'm talking with my book author. I'm used to read philosophy books, and believe me, I've never had the pleasure. Plato's is long away gone. :)

(you may read after the bold only). :)

Quote:
Well, I dunno if what you propose is actually doable, where you pass in an ID straight to the controller without even calling a function.
Yes. The all point was to avoid the duplication on the URI like /category/cat/ and product/prod/ or something like this.
I was trying to do that inside the index method of the controller, but, for actually make that work, I needed to explicitly write the /index/ on the URI, (since CI only passes segments values as variables after the second segment. (I believe we can change this, but I don't feel like)) - but, having /category/cat/ or /category/index/ it stills not to be a clean method for this site URIs.

But maybe it will be there where the Routing you have mentioned above, may help hm? I don't know because, here:
http://codeigniter.com/user_guide/general/routing.html
it seems that all the examples tend to work out solution for when a user types directly the url on the browser. But Maybe I'm wrong.

Anyway, I'm missing the point already:

I'm now having a method other then index on my controller to handle it.


Question:
on the first code snipped on page 91:

You have:
$data['category']=$cat;

I believe this is a key step on all this, but I don't quite get what does it do... let's see:

We are storing a specific category id coming from the 3th segment on our URI, to a variable name $cat, and, we have storing that $cat on an array key named category.

That array key among other keys, will then be loaded to be accessible on all views, and then, we load a template view to grab and work with that $data.

I now expect to see some $category somewhere... on the view file, since CI transforms keys to $vars (I don't recall the php function that does that) and, on page 96, here it is, or $category var.

If all this assumptions are correct:
I'm not quite getting, how can we just do something like $category->name for example, and grab the name.
If the $category as an ID on it, let's suppose, 3, it seems that we are telling: 3->name, and doesn't make sense...




Regards,
Márcio
 
Old September 1st, 2009, 11:52 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, after some sleep, I have look at the model, and I see that:


Quote:
"We are storing a specific category id coming from the 3th segment on our URI, to a variable name $cat"
is FALSE.

What I'm getting is a specific ROW data from my database, where an $id equals a specifc value that comes from the URI.


Hence, dissipating the doubts I was having on last post.



Regards,
Márcio
 
Old September 2nd, 2009, 08:15 AM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default so sorry!

I'm hammering away at various deadlines and didn't get a chance to come back here until just now. After the 15th of september, I will be more available.
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
 
Old October 12th, 2009, 09:53 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Thomas, once again,

I'm really REALLY trying hard to display a menu that could contain, not only two, but several sub categories.

http://codeigniter.com/forums/viewthread/128272/

http://codeigniter.com/forums/viewthread/128561/

No sucess, at all.

I'm following your book so, all the template and page structure, commes from your ideas, that I happen to understand. So, what I'd like to ask is:

You have give an example, where there's only one category and one subcategory. Can we use the same structure to accomplish the view for more then one sub-category? Can we use the same structure to work with n subcategories? Or, in order do allow n categories, we need to change a lot on this code structure?


If possible, please advice, I'm absolutly stuck here.

Regards,
Márcio





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Page links snufse ASP.NET 2.0 Basics 1 April 10th, 2008 11:57 PM
Page links in forum title jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 October 17th, 2007 04:37 PM
links to a page when a button is clicked hosefo81 HTML Code Clinic 4 December 7th, 2003 06:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.