Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:51:53+00:00 2026-05-23T18:51:53+00:00

just starting with cakephp and almost with php after a few years without use

  • 0

just starting with cakephp and almost with php after a few years without use it….

I have a table structure like this:
Parent table…… Clients:

<?php
class Cliente extends AppModel
{
    var $name = 'Cliente';
        var $validate = array(
                            'nombre' => array('rule'=>'notEmpty')
                             );
        var $hasMany = array(
            'Proyecto' => array(
                'className'  => 'Proyecto',
                'foreignKey' => 'cliente_id',
                'order'      => 'Proyecto.nombre ASC',
                'dependent'  => true                
            )
        );
}
?>

And child table: Proyects..
A client can have several projects assigned.

<?php
class Proyecto extends AppModel
{
    var $name = 'Proyecto';
        var $validate = array(
                            'nombre' => array('rule'=>'notEmpty')
                             );
        //var $belongsTo = 'Cliente';
        var $belongsTo = array(
            'Cliente' => array(
                'className' => 'Cliente',
                'foreignKey' => 'cliente_id'
            )
        );
}
?>

Proyects only can be added (INSERT) from the index client view. So, I have this add (anadir) method:

    function anadir($cliente_id, $nombre) {
        if (!empty($this->data)) {
//                        echo "El código de cliente 22222: ". $this->data['Proyecto']['id'] . "</br>";
//                        echo "El código de cliente fk: ". $this->data['Proyecto']['cliente_id'] . "</br>" ;
//                        print_r($this->data);
                        //$this->data['Proyecto']['cliente_id'] = $cliente_id;
            if ($this->Proyecto->save($this->data)) {
                $this->Session->setFlash('El proyecto ha sido grabado.');
                $this->redirect(array('controller'=>'clientes', 'action'=>'listar'));
            }
                } else {  
                        //echo "El código de cliente 11111: ". $this->data['Proyecto']['id'];                  
                    $this->data['Proyecto']['cliente_id'] = $cliente_id; 
                }
                $this->set('idcliente', $cliente_id);
                $this->set('nombrecliente', $nombre);
    }

I can show the parent client (id and number) in the ‘anadir.ctp’ view, but it always update the same proyect, changing the name and description only. No ADD/INSERT is done in the table, only UPDATE.

<!-- File: /app/views/proyectos/anadir.ctp -->  

<h1>A&ntilde;adir proyecto a cliente <?php echo "[$idcliente] - $nombrecliente"; ?></h1>
<?php
    //echo $this->Form->create('Proyecto', array('action' => 'anadir'));
    echo $this->Form->create('Proyecto', array('url' => '/proyectos/anadir/'.$idcliente.'/'.$nombrecliente)); // array('action' => 'anadir'));
    echo $this->Form->input('cliente_id', array('type' => 'hidden'));
    echo $this->Form->input('nombre');
    echo $this->Form->input('descripcion', array('rows' => '10'));
    echo $this->Form->end('Grabar proyecto');
    echo $this->Html->link('Cancelar', array('controller'=>'clientes', 'action'=>'listar'));
?>

Surely it is a newbie question but I have tried almost everything.

Any idea ?

Thanks in advance.

==== Finally ====

After a few days trying to solve this it is running now. But I cannot understand the problem and I have no explanation why I have had that weird problem…

So I am going to look forward symfony2 Perhaps more difficult to start with but I hope more flexible (with multi Primary Keys and foreign key support, mainly) and clear than cakephp.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:51:54+00:00Added an answer on May 23, 2026 at 6:51 pm

    So it still looks (as deizel suggested) that you’ve got id set in your $this->data somehow, probably a field with mistaken in a form, not sure (you can post your view here so we can take a look). The best way to check it is to monitor actual SQL queries; put this after $this->Model->save() (without adding $this->Model->create()yet, for debug purposes):

    $log = $this->Model->getDataSource()->getLog(false, false);
    debug($log);
    

    Add output of above to your question.

    Regarding $this->Model->create(): calling it prior to $this->Model->save() is perfectly ok and even recommended. It’s like variable initialization – you can skip it, but at your own risk, when you’re absolutely sure what you’re doing.

    To address Missing argument 1 for ProyectosController::anadir() error you should post your URL here. It should be something like /proyectos/anadir/2/10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting with ASP.NET and find it difficult to use the GridView. I have
Just starting to use Cruise Control, but can't seem to find anything on this
Just starting to use CodeIgniter, and I'd like to import some of my old
I am just starting to learn CakePHP, I have downloaded version 1.3.7. i noticed
Go easy, I'm just starting to learn CakePHP. I'm having to ask this question
Just starting with php and sorry if this is a newbie question but i'm
I'm just starting to try MacVIM as a primary text editor after years of
I am just starting to use Gaelyk. I was expecting it to behave like
Just starting out in asp.net. Have just created a login.aspx page in my site
Im just starting a project and since this project is personal I was wondering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.