Thursday, February 23, 2012

Re: Why data isn't showed?

read manual again !

models names are Country (singularized and camelized), and controllers are CountriesController (pluralized))
--
Lep pozdrav, Tilen Majerle



2012/2/23 reynierpm@gmail.com <reynierpm@gmail.com>
OK, I made some changes to my DB structure and also to my code but still getting errors, see below what I'm doing now. 
1) Change the table from countries to country and  also rename the composite PK from country_id to id
2) Change code in the Model, now looks like this:

<?php
class Country extends AppModel {
public $name = 'Country';
}

3) Change code in the Controller:
class CountryController extends AppController {
public $name = 'Country';
public $helpers = array("Html", "Form");
public $components = array("Session");

public function edit($id = null) {
$this->Country->id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Country->read();
} else {
if ($this->Countries->save($this->request->data)) {
$this->Session->setFlash(__('The country has been updated.'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Unable to update the country.'));
}
}
}

But I get this error:
Missing Database Table
Error: Database table countries for model Country was not found.
Why?
Ing. Reynier Pérez Mira



On Thu, Feb 23, 2012 at 8:29 AM, reynierpm@gmail.com <reynierpm@gmail.com> wrote:
So because CakePHP doesn't support compsite PK then the solution need to be change the field country_id for id and also in all the tables. Reading the conventions for Models I get one doubt and goes to oneToMany relations. If I have one relation oneToMany between tables candidate and education and I add the FK candidate_id in education table then CakePHP knows the relation by default? This is correct? Please can you take a look at my DB design and tell me if something is wrong there:  http://www.dropmocks.com/mBgrQq ?

Ing. Reynier Pérez Mira



On Thu, Feb 23, 2012 at 7:40 AM, Tilen Majerle <tilen.majerle@gmail.com> wrote:
http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html 

look here, cakephp conventions
--
Lep pozdrav, Tilen Majerle



2012/2/23 reynierpm@gmail.com <reynierpm@gmail.com>
Hi Tilen, I not understand your point here. As you said I have country_id as PK and my table is Countries not Country so my model code is this one (Countries.php):

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

then if I use $this->Country->id = $id doesn't work and if I use $this->Countries->country_id = $id doesn't work too. Which should be the solution? Change my table structure or what?

Ing. Reynier Pérez Mira



On Thu, Feb 23, 2012 at 5:02 AM, Tilen Majerle <tilen.majerle@gmail.com> wrote:
you have "country_id" as your primary key in table ?

and "Countries" for modelname ?
it should be "Country" right ? :)

$this->Countries->country_id = $id; //this is wrong
here should be ALWAYS "id", so $this->Countries->id = $id;

but u should use camelized and singularized name, so $this->Country->id = $id and it will work



VIEW:
Form::create(); here you should have the same model name as you pass data, "Country" and not CountryFrm
--
Lep pozdrav, Tilen Majerle



2012/2/23 reynierpm@gmail.com <reynierpm@gmail.com>
Hi every:
Take a look at this function:

public function edit($id = null) {
$this->Countries->country_id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Countries->read();
} else {
if ($this->Countries->save($this->request->data)) {
$this->Session->setFlash(__('The country has been updated.'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Unable to update the country.'));
}
}
}

Aparently all seems to be fine but surprise when I call edit method and pass a ID as parameter the data isn't showed in the template, why? Any help? This is the edit.ctp content:

<h1>Edit Country</h1>
<?php
    echo $this->Form->create('CountryFrm', array('action' => 'edit'));
    echo $this->Form->input('country_name');
    echo $this->Form->input('iso_code_2');
    echo $this->Form->input('iso_code_3');
    echo $this->Form->input('country_id', array('type' => 'hidden'));
    echo $this->Form->end('Save!!!');


Ing. Reynier Pérez Mira

--
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

--
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

--
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

--
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


--
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

--
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: