我想用json_encode将模型查询转换为json,它不起作用.但是使用普通阵列确实如此.
$arr = array("one", "two", "three");
$data["json"] = json_encode($arr);
Run Code Online (Sandbox Code Playgroud)
产量
<?php echo "var arr=".$json.";"; ?>
var arr=["one","two","three"];
Run Code Online (Sandbox Code Playgroud)
但是当我尝试转换查询时,codeigniter会抛出错误.那是什么意思?这是错误消息:
遇到PHP错误严重性:警告消息:[json](php_json_encode)类型不受支持,编码为null
转换后的"查询"结果=我的意思是模型方法是这样的:
{"conn_id":null,"result_id":null,"result_array":[],"result_object":[],"current_row":0,"num_rows":9,"row_data":null}
Run Code Online (Sandbox Code Playgroud)
我试着这样做
$posts = $this->Posts_model->SelectAll();
$data["posts"] = json_encode($posts);
Run Code Online (Sandbox Code Playgroud)
顺便说一句,当我没有json_encode时,模型和方法工作得很好.
我可能做错了什么,但问题是什么?
我正准备查询mySQL以获取前一周的记录,但我必须将周视为周一至周日.我原来是这样做的:
WHERE YEARWEEK(contactDate) = YEARWEEK(DATE_SUB(CURDATE(),INTERVAL 7 DAY))
Run Code Online (Sandbox Code Playgroud)
发现mySQL将周视为周日 - 周一.所以我正在解析在php中获取开始和结束日期,如下所示:
$i = 0;
while(date('D',mktime(0,0,0,date('m'), date('d')-$i, date('y'))) != "Mon") {
$i++;
}
$start_date = date('Y-n-j', mktime(0,0,0,date('m'), date('d')-($i+7), date('y')));
$end_date = date('Y-n-j', mktime(0,0,0,date('m'), date('d')-($i+1), date('y')));
Run Code Online (Sandbox Code Playgroud)
这是有效的 - 它获得当周的星期一(向后走,直到星期一被击中)然后根据该日期计算前一周的日期.
我的问题是:有更好的方法吗?看起来很草率,我希望那里有人可以给我一个更干净的方法 - 或许不是因为我需要周一 - 周日周.
显然,有:
$start = date('Y-m-d',strtotime('last monday -7 days'));
$end = date('Y-m-d',strtotime('last monday -1 days'));
Run Code Online (Sandbox Code Playgroud)
这大约是可读性的一百万倍.谢谢.
我有以下记录定义
E3Vector3T = packed record
public
x: E3FloatT;
y: E3FloatT;
z: E3FloatT;
function length: E3FloatT;
function normalize: E3Vector3T;
function crossProduct( const aVector: E3Vector3T ): E3Vector3T;
class operator add( const aVector1, aVector2: E3Vector3T ): E3Vector3T;
class operator subtract( const aVector1, aVector2: E3Vector3T ): E3Vector3T;
class operator negative( const aVector: E3Vector3T ): E3Vector3T;
class operator multiply( const aVector: E3Vector3T; const aScalar: E3FloatT ): E3Vector3T;
class operator divide( const aVector: E3Vector3T; const aScalar: E3FloatT ): E3Vector3T;
end;
Run Code Online (Sandbox Code Playgroud)
我想要做的是引入一个变体记录部分,以便能够单独和作为一个数组访问这三个元素,即
E3Vector3T = packed record
public …
Run Code Online (Sandbox Code Playgroud) 作为root mysql用户,我执行了以下操作:
grant all on mydb.* to john identified by 'john1';
Run Code Online (Sandbox Code Playgroud)
然后从shell,我尝试登录
mysql -h localhost -u john -pjohn1;
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我得到了错误
ERROR 1045 (28000): Access denied for user 'john'@'localhost' (using password: YES)
Run Code Online (Sandbox Code Playgroud)
如何让john登录mysql终端?我是否需要使用root mysql用户来更改mysql.user表中的内容?
谢谢
为什么我会收到discard qualifiers
错误:
customExc.cpp: In member function ‘virtual const char* CustomException::what() const’:
customExc.cpp: error: passing ‘const CustomException’ as ‘this’ argument of ‘char customException::code()’ discards qualifiers
Run Code Online (Sandbox Code Playgroud)
在下面的代码示例中
#include <iostream>
class CustomException: public std::exception {
public:
virtual const char* what() const throw() {
static std::string msg;
msg = "Error: ";
msg += code(); // <---------- this is the line with the compile error
return msg.c_str();
}
char code() { return 'F'; }
};
Run Code Online (Sandbox Code Playgroud)
在讨论类似问题之前,我已经搜索过SOF.
我已经const
在每个可能的地方添加了一个.
请赐教 - 我不明白......
编辑 …
在纸面上,二进制算法很简单,但作为一个初级程序员,我发现有点难以提出二进制数的加法,减法,乘法和除法算法.
我有两个二进制数存储为字符串,假设已删除任何前导零.我将如何对这两个数字执行这些操作?
编辑:我需要避免将它们转换为int或long.
我刚刚发现了Rails附带的一个rake任务中的一个错误.有没有办法修补rake任务?
必须支持IE6并且必须验证vs XHTML Strict 1.0!
这很难解释......
我正在使用通用类名来启动关联元素的插件功能.我还希望有一个与存储在属性中的元素相关的选项.
<a href="url.com" class="popup" rel="900x900" >My Link</a>
Run Code Online (Sandbox Code Playgroud)
有了这个,jQuery将查找所有具有'popup'的元素并解析弹出窗口维度的rel值,并在每次使用大小为w = 900 h = 900的窗口单击此链接时启动popup()函数
但我需要更进一步,因为我想有更多的选择......
<a href="url.com" class="popup" rel="900x900_scroll_tool_menu" >My Link</a>
Run Code Online (Sandbox Code Playgroud)
我不确定是否使用rel属性是因为我还想在其他没有rel =属性的元素上使用它.
所以我也在考虑使用类...我想出了这个:
<a href="url.com" class="popup opt_dim-900x900_scroll_tool_menu" >My Link</a>
<img src="pic.gif" class="popup opt_dim-150x200_location" >My Link</a>
Run Code Online (Sandbox Code Playgroud)
从外观来看,选项可以变得非常长,使用类似乎没问题,但也许有更好的东西..
你认为哪种方式更好?你对此有另一个想法吗?我想将选项存储在某些html属性中.
谢谢!
UPDATE
我不断被提醒,有十几种方法可以在Javascript中做任何事情,就这里的解决方案而言,我后来改变了对html5数据属性的正确答案,现在ie6不是问题,看起来是最好的方法.
最好,因为它使用标准功能,并避免了我试图用类名做的任何hackery.确实类名仍然非常灵活,但该解决方案不是语义,也不遵循将视图与行为分离的最佳实践.
我从一个exe内部运行一个WCF服务(用于调试,它将在部署时移动到Windows服务)我有一个服务在其中运行良好但是当我运行第二个服务时我得到异常
System.InvalidOperationException was unhandled
Message=The ChannelDispatcher at 'http://backupsvr:8082/' with contract(s) '"IHttpGetHelpPageAndMetadataContract"' is unable to open its IChannelListener.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at Service.Program.Main() in E:\Visual Studio 2010\Projects\Contract Flow Suite\Service\Program.cs:line 30
InnerException: System.InvalidOperationException
Message=A registration already exists for URI 'http://backupsvr:8082/'.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan …
Run Code Online (Sandbox Code Playgroud) 我在IIS上创建了一个多线程应用程序(ASP.NET MVC),当线程服务器启动时,它创建了10个线程,并将工作项目引入线程.
通常我的应用程序运行良好,但有一段时间我有错误,我确信问题来自流畅的配置.我再次确定我犯了一些错误:)
这是我的SessionFactory类:
public class NHibernateHelper
{
private static ISessionFactory sessionFactory;
/// <summary>
/// SessionFactory is static because it is expensive to create and is therefore at application scope.
/// The property exists to provide 'instantiate on first use' behaviour.
/// </summary>
private static ISessionFactory SessionFactory
{
get
{
if (sessionFactory == null)
{
sessionFactory = CreateSessionFactory();
}
return sessionFactory;
}
}
/// <summary>
/// CreateSessionFactory
/// </summary>
/// <returns></returns>
private static ISessionFactory CreateSessionFactory()
{
IPersistenceConfigurer dbConfigurer = MsSqlConfiguration.MsSql2005 …
Run Code Online (Sandbox Code Playgroud)