(codeigniter / Neo4j)PHP:名称空间和自动加载器((codeigniter/Neo4j) PHP : namespace and autoloader)
当我试图在codeigniter(v2.2.x)中安装Neo4jPHP库时,我遇到了有关名称空间的恼人问题。 我一直在寻找4个小时没有成功。
简而言之,有一个库目录,其中必须复制Neo4jPHP。 所以在'libraries /'中,有一个目录'Everyman / Neo4j /',它包含所有Neo4j php类。
此外,在相同的'libraries'目录中,有一个带有自动加载器功能的类,其目的是加载Neo4j类(在'Everyman / Neo4j /'中)。
在'图书馆'里面
- libraries/ |-- Everyman/ |-- Neo4j/ |-- Client.php |-- some_other_classes.php |-- Neo4j.php
然后,在我的代码中的某个地方,在全局命名空间中,我尝试实例化类客户端:
$client = new Client();
但我得到错误类'客户'未找到 。
在类客户端中,指定了以下命名空间: Everyman \ Neo4j 。
我必须承认我找到了2个解决此问题的方法:
从调用代码中,使用完全限定名称:
new Everyman\Neo4j\Client();
或者,在Client.php中,删除命名空间。
在这两种情况下,它的工作原理。 但是,我想用这两个条件调用Client类:1。我不想修改Neo4jPhp库中的任何内容。 2.我真的不想使用完全限定名称(Everyman \ Neo4j \ Client)。 我想使用“new Client()”。
你们是否知道如何实现这一点(是的,我对命名空间和加载器没有非常深刻的理解)。
在Neo4j.php(带加载程序的文件)
<?php class Everyman{ public function __construct() { spl_autoload_register(array($this,'autoload')); } public function autoload($sClass){ $sLibPath = __DIR__.DIRECTORY_SEPARATOR; //Below, i modified the instruction so that the class file //can be found. However, the class is not found. $sClassFile = 'Everyman'.DIRECTORY_SEPARATOR.'Neo4j'.str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php'; $sClassPath = $sLibPath.$sClassFile; if (file_exists($sClassPath)) { require($sClassPath); } } }
就是这样了。 我想我已经把你所有的信息都告诉了你。 如果没有人可以帮助我,我将不得不使用'new Everyman \ Ne4j \ Client();' (有效)。
寻求帮助似乎很愚蠢,因为我已经找到了2个解决方法,但我真的想学习如何正确处理这个问题(如果可能的话)。
谢谢。
As i'm trying to install the Neo4jPHP library in codeigniter (v2.2.x), i'm having annoying issues regarding namespaces. I've been searching for 4 hours without success.
In short, there is a libraries directory in which Neo4jPHP must be copied. So in 'libraries/', there is a directory 'Everyman/Neo4j/', which contains all the Neo4j php classes.
Also, in the same 'libraries' directory, there is a class with an autoloader function, which aims at loading the Neo4j classes (which are in 'Everyman/Neo4j/').
Inside of 'libraries'
- libraries/ |-- Everyman/ |-- Neo4j/ |-- Client.php |-- some_other_classes.php |-- Neo4j.php
Then, somewhere in my code, in the global namespace, i try to instantiate the class client :
$client = new Client();
But i get the error Class 'Client' not found.
In the class client, the following namespace is specified : Everyman\Neo4j.
I'm must admit that i found 2 workarounds for this issue :
From the calling code, use the fully qualified name :
new Everyman\Neo4j\Client();
Or, in Client.php, remove the namespace.
In these 2 cases, it works. However, i would like to call the Client class with these 2 condition : 1. I don't want to modify anything from the Neo4jPhp library. 2. I really don't want to have to use the fully qualified name (Everyman\Neo4j\Client). I want to use "new Client()".
Do you guys have an idea how i could achieve this (yes, i don't have a very deep understanding of namespaces, and loaders).
In Neo4j.php (file with loader)
<?php class Everyman{ public function __construct() { spl_autoload_register(array($this,'autoload')); } public function autoload($sClass){ $sLibPath = __DIR__.DIRECTORY_SEPARATOR; //Below, i modified the instruction so that the class file //can be found. However, the class is not found. $sClassFile = 'Everyman'.DIRECTORY_SEPARATOR.'Neo4j'.str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php'; $sClassPath = $sLibPath.$sClassFile; if (file_exists($sClassPath)) { require($sClassPath); } } }
So that's it. I think i've given you all the information i have. If no one can help me, i'll have to use 'new Everyman\Ne4j\Client();' (which works).
It may seem stupid to ask for help, as i already have found 2 workarounds, but i really want to learn how to properly handle this issue (if possible).
Thanks.
原文:https://stackoverflow.com/questions/32194973
最满意答案
相反,为什么不使用BackgroundWorker启动长时间运行的任务并报告进度?: WPF多线程:使用BackgroundWorker并将进度报告给UI 。
事实上,WPF拥有自己的机制,称为Dispatcher:使用Dispatcher 构建更具响应性的应用程序
Instead, why not start the long running task using a BackgroundWorker and report progress?: WPF Multithreading: Using the BackgroundWorker and Reporting the Progress to the UI.
In fact, WPF has it's own mechanism called the Dispatcher: Build More Responsive Apps With The Dispatcher
相关问答
更多-
相反,为什么不使用BackgroundWorker启动长时间运行的任务并报告进度?: WPF多线程:使用BackgroundWorker并将进度报告给UI 。 事实上,WPF拥有自己的机制,称为Dispatcher:使用Dispatcher 构建更具响应性的应用程序 Instead, why not start the long running task using a BackgroundWorker and report progress?: WPF Multithreading: Using the ...
-
您可以直接从C#使用VB.Net InputBox string input = Microsoft.VisualBasic.Interaction.InputBox("My Prompt", "The Title", "Desired Default", ...
-
您缺少该按钮的Click-handle。 改变这个: Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 这样的事情: Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click Yo ...
-
MessageBox变量(MessageBox variable)[2022-07-06]
当我进行搜索并且输入没有找到匹配项时,此消息框出现......我需要将它用于多个例外 MessageBox没有任何公共构造函数,所以你不能创建它并分配给一个变量。 但是如果你想在不同的地方执行相同的代码,你可以像这样声明一个Func委托: FuncshowMsgBox = () => MessageBox.Show("No such thing", "Warning"); 并把它称为无论你想显示消息框: showMsgBox(); 如果你不关心返回值,你可以使用Action ... -
Microsoft解释了如何进行线程安全调用。 以下是他们网站上的示例: private delegate void SetTextCallback(string text); private void SetText(string text) { if (textBox1.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetText); Invoke(d, new object[] ...
-
这个问题的解决方案不在于ASP或VB代码,而是在服务器上设置Oracle。 对于将来遇到类似问题的任何人,我建议查看TNS_ADMIN环境/系统变量和TNSNAMES.ORA文件,并确保它们是正确的。 如果进行任何这些更改,请确保重新启动服务器。 我的步骤涉及验证TNSNAMES.ORA文件是否正确,设置了TNS_ADMIN环境变量,然后在cmd提示符中使用“set tns_admin = {filepath}”,然后重新启动服务器并且网站运行正常。 The solution to this problem ...
-
通常你不能这样做,最好不要这样做。 你应该看到这里。 他们可能有一个解决方案;-) 如何对接入的winform -文本框-控制-从-另一级 I managed to come up with a solution, see https://stackoverflow.com/a/21310270/2952390 (answer to a related question I asked previously). Here it retrieves text from a combobox to a labe ...
-
为什么MessageBox不显示?(Why MessageBox isn't showing?)[2023-06-25]
你永远不会调用log_in_Click 。 WPF不会从名称中猜出您想要将其与按钮关联。 您必须明确地将其设置为按钮的点击处理程序,如下所示:如果Hans Passant发布了答案而不是评论,我会将他的回答标记为答案。 这就是我解决问题的方法: DialogResult result = MessageBox.Show(t2tWindow, "The Style field did not pass validation. Please manually fix the data then click OK to continue.", "WARNING ...MessageBox本身泵出一个消息循环。 那当然不是Windows Forms消息循环。 一切都正常运行,但减去Control.BeginInvoke()发布的委托调用请求的调度。 只有Windows窗体消息循环可以做到这一点。 当在UI线程上进行MessageBox.Show()调用时会发生这种情况。 但是当它在工作线程上创建时,消息队列是每线程属性。 如果您可以将Show调用委托给工作人员,则可能会解决您的问题。 解决你的问题: 你真的想要相反:工作线程应该阻止。 不阻塞可能会导致重大问题,Begin ...相关文章
更多- CI快速入门-php项目实战之CodeIgniter
- CI完整MVC案例-php项目实战之CodeIgniter
- 《PHP框架之CodeIgniter留言板实例开发系列》更新至第5讲[RMVB]
- 图形数据库、NOSQL和Neo4j(转载)
- 图形数据库、NOSQL和Neo4j
- 图形数据库、NOSQL和Neo4j
- 图形数据库、NOSQL和Neo4j
- PHP简介
- 系统升级: PHP(5.1.6->5.4.7) & CI(1.7.2->2.1.2)调查记录
- php匹配问题
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。