我使用我的PHP后端通过检查值来检测AJAX请求$_SERVER['HTTP_X_REQUESTED_WITH'].
这为我提供了可靠的检测,确保使用AJAX技术进行请求.
如何确保请求来自我自己的域,而不是外部域/机器人?
www.example.com/ajax?true可以允许任何人拨打AJAX电话并剪切信息.
我可以为正常进入我网站的每个人制作会话,然后允许AJAX调用..但这也可以伪造.
这些天有甚么重要吗?
我将ZfcUser设置为身份验证模块.该模块运行良好,除了我必须在每个操作中再次定义它:
$sm = $this->getServiceLocator();
$auth = $sm->get('zfcuser_auth_service');
if ($auth->hasIdentity()) {
fb($auth->getIdentity()->getEmail());
}
else return $this->redirect()->toRoute('zfcuser');
Run Code Online (Sandbox Code Playgroud)
我尝试将代码放入构造中,但这并没有成功.然后我检查了服务管理器,但无法正确定义所有出现的多个版本.
这是我的Module类的代码:
public function getServiceConfig() {
return array(
'factories' => array(
'Todo\Model\TodoTable' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new TodoTable($dbAdapter);
return $table;
},
),
);
}
Run Code Online (Sandbox Code Playgroud)
如何正确设置服务?
我在共享服务器上设置ZF2.它在localhost上运行完美,但在共享服务器上我收到此错误:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/82/5123082/html/tmp/ZendSkeletonApplication/public/index.php on line 12
Parse error: syntax error, unexpected T_STRING in /home/content/82/5123082/html/tmp/ZendSkeletonApplication/public/index.php on line 12
Run Code Online (Sandbox Code Playgroud)
在index.php代码的第12行:
Zend\Mvc\Application::init(include 'config/application.config.php')->run()->send();
Run Code Online (Sandbox Code Playgroud)
帐户运行的PHP版本: PHP 5.3.13(cli)(内置:2012年5月14日16:26
使用的Linux服务器是: Linux ... secureserver.net ...#1 SMP Fri Jul 15 08:15:44 EDT 2011 i686 i686 i386 GNU/Linux CentOS 5.5版(最终版)
我没有使用doctorine - 它现在甚至没有加载Skeleton应用程序 - 好像命名空间有问题,并且它没有加载它.这就好像PHP版本运行不是PHP 5.3.
有什么想法我做错了什么?我尝试通过作曲家安装它,并从我的本地机器上传一个工作解决方案,但都没有工作..
我一直在尝试为一个字段订购ASC / DESC呼叫(比如说craeted),但我似乎无法弄清楚如何在ZF2中做到这一点。
我在哪里错了..?
namespace Todo\Model;
class TodoTable extends AbstractTableGateway {
public function __construct(Adapter $adapter) {
$this->adapter = $adapter;
$this->resultSetPrototype = new ResultSet();
$this->resultSetPrototype->setArrayObjectPrototype(new Todo());
$this->initialize();
}
public function fetchAll() {
$resultSet = $this->select(array('user_id'=>$this->user_id));
return $resultSet;
}
}
Run Code Online (Sandbox Code Playgroud) 让我们首先说我的代码完全正常,没有问题.我只是想用一个很好的类来包装它以便将来动态使用,我想知道如何以最正确的方式在Javascript中做到这一点.
load_server是一个放置Ajax请求的函数.pagination()/ itemlinks()是遍历检索到的数据并标记链接以供将来使用Ajax的函数.我目前在函数中编写所有内容并将其转储到代码中,但我想创建类似于:
function ajaxRequest(type, link, container) {
this.after_success = null;
this.check_pagination = true;
if(typeof(type)) == ‘undefined’) this.type='';
if(typeof(link)) == ‘undefined’) this.link='';
if(typeof(container)) == ‘undefined’) this.container='';
this.pagination=function() {
//static function..
};
this.load_server=function () {
//function logic here..
};
while(mainReq.after_success) {
func();
}
}
var mainReq = new ajaxRequest{'link'};
mainReq.after_success = {
itemlinks = function() { },
morefunc = function() { }
};
mainReq.submit();
Run Code Online (Sandbox Code Playgroud)
我目前使用以下jQuery代码:
load_server = function (type, link, container) {
$(container).html("<div class='mask-loading'>Loading ...</div>");
$(container).load(getUrl,
function(responseText, textStatus, XMLHttpRequest) { //Callback …Run Code Online (Sandbox Code Playgroud)