Zend_Form ::何时应该在视图中创建表单而不是在控制器中?
选项1 - 在控制器中创建的表单并传递给视图(通常使用)
控制器:
$form=new MyForm();
$this->view->form=$form;
Run Code Online (Sandbox Code Playgroud)
视图:
echo $this->form;
Run Code Online (Sandbox Code Playgroud)
选项2 - 直接在视图中创建的表单(看起来更好,因为形成其子视图)
视图:
$form=new MyForm();
echo $this->form;
Run Code Online (Sandbox Code Playgroud)
谢谢
Zend newbie here ...为了让它变得更好,我的使命是建立在其他人已经存在的Zend网站之上.
(BTW:zf show version - > Zend Framework Version:1.11.1 - 我似乎有Zend_Form).
这是好奇的一点.所有表单都在视图中以HTML格式构建.他们似乎工作,虽然我无法弄清楚 - 特别是考虑到我所看到的.
我遵循惯例并为测试表单创建了一个视图并编写了表单:
<form action="<?php echo $this->url(array('controller'=>'ControllerName','action'=>'submit'));?>" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit"/>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
控制器中的submitAction成员正确触发.没问题.
但我可以查找POST数据的所有地方似乎都是空的!
echo "obj custEmail = [" . $this->_request->getPost('custEmail') . "]\n";
echo "GET custEmail = [" . $_GET['custEmail'] . "]\n";
echo "POST custEmail = [" . $_POST['custEmail'] . "]\n";
if ($this->_request->isPost()) {
$data …Run Code Online (Sandbox Code Playgroud) 我有一个Zend Framework控制器editAction().
class WidgetController extends BaseController
{
public function editAction()
{
//code here
}
}
Run Code Online (Sandbox Code Playgroud)
该控制器扩展了一个基本控制器,该控制器在允许用户编辑记录之前检查用户是否已登录.
class BaseController extends Zend_Controller_Action
{
public function init()
{
if ($this->userNotLoggedIn()) {
return $this->_redirect('/auth/login');
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,现在我正在执行AJAX请求,我将返回一个JSON响应,因此重定向将不再起作用.我需要停止进一步的控制器执行,以便我可以立即发送响应:
class BaseController extends Zend_Controller_Action
{
public function init()
{
if ($this->userNotLoggedIn()) {
if ($this->_request->isXmlHttpRequest()) {
$jsonData = Zend_Json::encode(array('error'=>'You are not logged in!'));
$this->getResponse()
->setHttpResponseCode(401)
->setBody($jsonData)
->setHeader('Content-Type', 'text/json');
//now stop controller execution so that the WidgetController does not continue
} else {
return $this->_redirect('/auth/login');
} …Run Code Online (Sandbox Code Playgroud) 一些用户上传了存储在目录中的机密合同/协议文件/var/www/html/project/public/contract/<HERE_UNIQUE_FILES.pdf>.
但问题是来自谷歌搜索或直接链接任何未经授权的用户可以打开它并查看/复制它.
我如何保护它,以便只有我的域或允许的对等方只能访问此私人目录?
例:
class Application_Model_Uploader
{
public static function mvUploadContract()
{
/* Anyone from outside can access this path, but how to protect it? */
$target_path = APPLICATION_PATH . "/../public/contract/";
$target_path = $target_path . basename( $_FILES['contractfile']['name']);
if(move_uploaded_file($_FILES['contractfile']['tmp_name'], $target_path))
{
$result = true;
}else{
$result = false;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我是Zend Framework的新手.有没有办法从我的活动控制器访问位于另一个模块中的模型类表?作为ZF3中的再见服务定位器,我无法访问位于其他模块中的模型类表.
以前在ZF2控制器中
private configTable;
public function getConfigTable()
{
if (!$this->configTable) {
$sm = $this->getServiceLocator();
$this->configTable = $sm->get('Config\Model\ConfigTable'); // <-- HERE!
}
return $this->configTable;
}
public function indexAction(){
$allConfig = $this->getConfigTable()->getAllConfiguration();
......
}
Run Code Online (Sandbox Code Playgroud)
由于服务定位器足以将函数从控制器调用到位于另一个模块中的模型类.有没有办法在没有服务定位器的ZF3中实现类似的东西?
先谢谢你们.再见!
php zend-framework zend-controller zend-framework2 zend-framework3
我已经在Zend Framework工作了一段时间,我目前正在重构代码的某些部分.其中一个大的事情,我想消除是我的abstract控制器类引发了很多必须存在于我所有的控制器,如变量$success,$warning和$error.这部分可以在控制器插件中完成,但是将这些变量发送到相关视图的最佳方法是什么.目前我在我的abstract控制器类中使用自定义方法,我在所有控制器中调用.
protected function sendViewData(){
$this->view->success = $this->success;
$this->view->warning = $this->warning;
$this->view->error = $this->error;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的所有控制器的所有动作中调用它
parent::sendViewData();
Run Code Online (Sandbox Code Playgroud)
我希望通过插件控制器或更适合此的任何东西来自动执行此过程
HII ...
我有这样的功能......
class Zend_View_Helper_RenderUOList extends Zend_View_Helper_Abstract {
public function makeUOList($inputArray, $main = true, $id ="", $class="")
{
------
------
------
$output .= "<li>" . $value['name'] . "\n";
$output .= makeUOList($value, false, '', '');
$output .= "</li>\n";
Run Code Online (Sandbox Code Playgroud)
我试图在函数内调用相同的函数,我收到一条错误消息作为致命错误:在C:\ dev\workspaces\adxweb\library\Zend\View\Helper\RenderUOList中调用未定义函数makeUOList().第99行的PHP
我出错的任何帮助...提前.