Tuesday, December 6, 2011

Re: Assistance with Blog Tutorial

Your code looks a bit non-standard. What's ItemKey1? And field name are normally lower camel case.

Try this (assuming you primary key on the items table is 'id' and your description field is 'item_description'):

public function view($id = null) {
$this->set(
'item',
$this->Item->find(
'first',
array('Item.id' => $id)
)
);
 }

Then in your view:

<?php
echo $this->Html->link(
$item['Item']['item_description'],
array(
'controller' => 'items',  <=== note the controller is all lower case
'action' => 'view',
$item['Item']['id']
)
);
?>

Jeremy Burns
Class Outfit


On 4 Dec 2011, at 23:2743, davfergus wrote:

Good evening,

Rookie developer, in MVC for 6 months, CakePHP for about 1.  My
current tests with Cake can be seen at: http://174.129.130.149/items

I am experiencing an issue on the drill down.  I paste everything into
a text doc so I could do a line by line but the issue is eluding me.

I can successfully see all items of my table.  I can click the link
and go from index.ctp to view.ctp.  My id passes successfully.  No db
data shows on view.ctp, but there are no errors.  The test var in item
2 below displays.  I cast $id as an (int) and did a gettype to test,
and it came back as an int.  Still no luck?  I am assuming I am
missing something quite simple, but after three hours of looking at
this I obviously do not know what I am looking at.

1. app/Model/Item.php

 class Item extends AppModel {
   public $name = 'Item';
 }

2. app/Controller/ItemsController.ctp contains the following (index()
works like a champ):
 public function view($id = null) {
   $this->Item->ItemKey1 = $id;
   $this->set('item', $this->Item->read());
   $this->set('testvar', 'it is set');
 }

 index successfully executes find('all');

3. app/View/Items/view.ctp  contains the line: echo $item['Item']
['DBField']; and echo $testvar;

 a. index.ctp does the following: <?php echo $this->Html-
link($item['Item']['ItemDescription'], array('controller' => 'Items',
'action' => 'view', $item['Item']['ItemKey1']) ); ?>
   the link works and I go to the correct page, I do a view source
and everything is there minus any data from the db.  I've tried
changing item names to upper case, adding an 's', but each changes
throws an error.  I thought the issue was the id coming in as a string
so I cast to an int, still no dice.

R/s,
Dave

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: