gpt4 book ai didi

php - Zendframework 2 骨架应用程序 Albumform 样式丢失

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:35 25 4
gpt4 key购买 nike

我目前正在 ZF2 中重建骨架应用程序在“Zend Framework 2 文档,版本 2.3.3”中,有一个用于添加/编辑相册的表单。

在文档中,表单如下所示: zendframework example

我一步一步地按照文档操作,但我的看起来像这样: zendframework example mine

AlbumForm.php:

<?php
namespace Album\Form;

use Zend\Form\Form;

class AlbumForm extends Form
{
public function __construct($name = null)
{
parent::__construct('album');

$this->add(array(
'name' => 'id',
'type' => 'Hidden',
));
$this->add(array(
'name' => 'title',
'options' => array(
'label' => 'Title',
),
'attributes' => array(
'type' => 'text',
)
));
$this->add(array(
'name' => 'artist',
'options' => array(
'label' => 'Artist',
),
'attributes' => array(
'type' => 'text',
)
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}

添加.phtml

<?php

$title = 'Add new album';
$this->headTitle($title);
?>

<h1><?= $this->escapeHtml($title); ?></h1>

<?php

$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('artist'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

HTML 输出:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add new album - ZF2 Tutorial</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Le styles -->
<link href="/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css">
<link href="/css/bootstrap-theme.min.css" media="screen" rel="stylesheet" type="text/css">
<link href="/css/style.css" media="screen" rel="stylesheet" type="text/css">
<link href="/img/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
<!-- Scripts -->
<!--[if lt IE 9]><script type="text/javascript" src="/js/html5shiv.js"></script><![endif]-->
<!--[if lt IE 9]><script type="text/javascript" src="/js/respond.min.js"></script><![endif]-->
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><img src="/img/zf2-logo.png" alt="Zend Framework 2"/>&nbsp;Tutorial</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/">Home</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">

<h1>Add new album</h1>

<form action="&#x2F;album&#x2F;add" method="POST" name="album" id="album"><input type="hidden" name="id" value=""><label><span>Title</span><input name="title" type="text" value=""></label><label><span>Artist</span><input name="artist" type="text" value=""></label><input name="submit" type="submit" id="submitbutton" value="Add"></form> <hr>
<footer>
<!--<p>&copy; 2005 - 2014 by Zend Technologies Ltd. All rights reserved.</p>-->
</footer>
</div> <!-- /container -->
</body>
</html>

我希望有人知道我的错误是什么......

最佳答案

如果您使用 bootstrap3,则需要为输入字段添加适当的类所以你需要像这样改变你的 albumform.php:

    <?php
namespace Album\Form;

use Zend\Form\Form;

class AlbumForm extends Form
{
public function __construct($name = null)
{
parent::__construct('album');

$this->add(array(
'name' => 'id',
'type' => 'Hidden',
));
$this->add(array(
'name' => 'title',
'options' => array(
'label' => 'Title',
),
'attributes' => array(
'type' => 'text',
'class' => 'form-control',//changed line
)
));
$this->add(array(
'name' => 'artist',
'options' => array(
'label' => 'Artist',
),
'attributes' => array(
'type' => 'text',
'class' => 'form-control',//add form-control class
)
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
'class' => 'btn btn-default'//add btn class
),
));
}
}

添加.phtml:

    <?php

$title = 'Add new album';
$this->headTitle($title);
?>

<h1><?= $this->escapeHtml($title); ?></h1>

<?php

$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo '<br>';//separate line
echo $this->formRow($form->get('artist'));
echo '<br>';//separate line
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

谢谢你..

关于php - Zendframework 2 骨架应用程序 Albumform 样式丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26159554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com