Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以cakephp的形式使新输入字段与现有输入字段相似_Php_Forms_Cakephp - Fatal编程技术网

如何以cakephp的形式使新输入字段与现有输入字段相似

如何以cakephp的形式使新输入字段与现有输入字段相似,php,forms,cakephp,Php,Forms,Cakephp,您好,我是cakephp的初学者,我喜欢在admin side add.ctp中添加一个输入字段,我从未使用过,但我知道这个mvc结构,所以我尝试复制并粘贴现有的输入字段“name”,我只是复制了相同的代码,只将名称更改为“sidename”,工作正常。我还在相应的表中创建了一个名为“sidename”的数据库字段 我不熟悉模型和控制器,我只需要知道以下几点 当我们在表单中添加新字段时,需要更新哪些内容和文件(模型、视图、控制器)来保存数据 如果我想要更新,这里的意思是我在代码中使用了helpe

您好,我是cakephp的初学者,我喜欢在admin side add.ctp中添加一个输入字段,我从未使用过,但我知道这个mvc结构,所以我尝试复制并粘贴现有的输入字段“name”,我只是复制了相同的代码,只将名称更改为“sidename”,工作正常。我还在相应的表中创建了一个名为“sidename”的数据库字段

我不熟悉模型和控制器,我只需要知道以下几点

  • 当我们在表单中添加新字段时,需要更新哪些内容和文件(模型、视图、控制器)来保存数据

  • 如果我想要更新,这里的意思是我在代码中使用了helper类,那么我需要在哪里更新呢

  • 一旦它存储了数据库,就意味着如何在ctp文件中检索类似的内容

  • 现有代码(我需要在下面的代码中添加新的字段侧名??)

    在此处输入代码
    
    大家好,欢迎来到cakephp的精彩世界

    因此,如果你在公司中添加一个字段,在数据库中添加一个字段,基本上就完成了。Cakephp为您做其他一切。我正在猜测您的模型和使用此信息的页面,但它将使用与表单数据其余部分相同的约定显示

    在您的控制器中使用

    $general = $this->General-> find ('all');
    
    将获取数据库中的所有行,然后使用

    $this->set ('general', $general);
    
    这将在视图中设置一个名为general的变量

    从这个角度看,你可以

    Foreach ($general as $key => $value){
    $sirname = $value['General']['sirname'];
    }
    

    希望这有帮助。对不起,我在手机上浪费了一些时间。如果您发布更多的代码,我们肯定可以提供更多帮助,甚至可以编写您需要的代码。特别是您的控制器和视图。

    您应该使用PHP/cakePHP中的现代和更好的功能,如
    compact()

    这看起来可能并不比像上面那样在短期内设置每个变量好,但让我给你们一个更大的图景

    $variable_to_pass1 = $this->YourModel->find('all');    
    $variable_to_pass2 = $this->YourModel->find('all');    
    $variable_to_pass3 = $this->YourModel->find('all');    
    $variable_to_pass3 = $this->YourModel->find('all');    
    $variable_to_pass4 = $this->YourModel->find('all');    
    $variable_to_pass5 = $this->YourModel->find('all');    
    $variable_to_pass6 = $this->YourModel->find('all');
    $variable_to_pass7 = $this->YourModel->find('all');
    $variable_to_pass8 = $this->YourModel->find('all');
    $variable_to_pass9 = $this->YourModel->find('all');
    
    你的老年方法:

    $this->set ('variable_to_pass1', $variable_to_pass9);
    $this->set ('variable_to_pass2', $variable_to_pass9);
    $this->set ('variable_to_pass3', $variable_to_pass9);
    $this->set ('variable_to_pass4', $variable_to_pass9);
    $this->set ('variable_to_pass5', $variable_to_pass9);
    $this->set ('variable_to_pass6', $variable_to_pass9);
    $this->set ('variable_to_pass7', $variable_to_pass9);
    $this->set ('variable_to_pass8', $variable_to_pass9);
    $this->set ('variable_to_pass9', $variable_to_pass10);
    
    现代方法(减少了麻烦:)也减少了代码行

    视图中
    可以这样使用,就像控制器中设置的变量一样使用

    echo $variable_to_pass1;
    

    如果它在数组中,那么您在foreach中的$variable\u to\u pass1中得到的是什么。

    我认为您的问题与这个问题相同

    您需要通知cakephp数据库中有新字段


    我只想让你们知道一件事,我刚才只在ctp文件中添加了这段代码echo$this->Form->input('sidename',array('label'=>l('sidename'));然后我用新的字段“sidename”更新了我的表,你说这足以将数据保存在db中。但在我提交表单后,它不会在我的数据库中更新table@Rymn注意你的语言,这不是胡说八道。我给出了两种选择,并提出了更好的选择。这些都在食谱中给出。如果你不知道,那就读一读,如果OP有任何问题,那就直接问。这是一个非常基本的问题,已经在Cakephp食谱中得到了回答。我想你是对的,这是一个学习和发现的地方。我还想补充一点,如果每个人都阅读了文档,那么这个网站就不存在了……我建议你先阅读cakephp食谱。它清除了所有的基本概念。检查这里:你检查了吗?
    $this->set ('variable_to_pass1', $variable_to_pass9);
    $this->set ('variable_to_pass2', $variable_to_pass9);
    $this->set ('variable_to_pass3', $variable_to_pass9);
    $this->set ('variable_to_pass4', $variable_to_pass9);
    $this->set ('variable_to_pass5', $variable_to_pass9);
    $this->set ('variable_to_pass6', $variable_to_pass9);
    $this->set ('variable_to_pass7', $variable_to_pass9);
    $this->set ('variable_to_pass8', $variable_to_pass9);
    $this->set ('variable_to_pass9', $variable_to_pass10);
    
    $this->set(compact('variable_to_pass1','variable_to_pass2','variable_to_pass3','variable_to_pass4','variable_to_pass5','variable_to_pass6','variable_to_pass7','variable_to_pass8','variable_to_pass9'));
    
    echo $variable_to_pass1;