我想用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时,模型和方法工作得很好.
我可能做错了什么,但问题是什么?
我正在研究CodeIgniter应用程序.
我有一个视图,我们称之为Calendar,其中包含一个JS/jQuery <script>块.看起来像这样:
$(document).ready(function() {
$("#day_list").fadeIn(600);
// init
var current_month = <?= $init['current_month']; ?>;
var current_year = <?= $init['current_year'] ?>;
// previous, next month ajax call
$(".previous, .next").click(function(event) {
// do stuff to these variables, then ajax call.
$.ajax({
// ajax
});
});
});
Run Code Online (Sandbox Code Playgroud)
在另一个视图中,我的页脚,我有另一个脚本块,它应该使用相同的变量(current_month和current_year).但是,它不知道它们的存在.将这些变量从第一个<script>块传递到另一个块的最快,最简单的方法是什么?由于构建应用程序的方式,我无法将这两个块放在一起.我应该为它写一个函数来获取并返回这些值(我应该怎么做?我是一个新手)还是有更简单的方法?
非常感谢!
在CodeIgniter Project中,我通常使用以下命令来执行sql.
$res = $this->db->select('*')
->from('customer')
->where('customer.id', $id)
->get();
Run Code Online (Sandbox Code Playgroud)
但不幸的是我的PHP Storm(5.0)不支持多个自动完成(我不知道怎么说)
例如在netbeans中如果我键入
$res = $this->db->select('*')->
Run Code Online (Sandbox Code Playgroud)
它将自动弹出该功能的其余部分.但在PHPStorm它并没有畏缩.它的工作一级自动完成.
我想在codeigniter中创建一个数据库备份工具.所以我想从控制器中获取数据库名称.我该怎么办呢.谢谢你的回答.
我正在尝试在CodeIgniter上设置SMTP.一切正常,我在页面上收到成功消息,发送的电子邮件没有错误.但是,电子邮件未送达.
这是我使用的代码:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'my-email@gmail.com',
'smtp_pass' => '***',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('my-email@gmail.com', 'Explendid Videos');
$this->email->to('my-email@gmail.com');
$this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
$this->email->subject('Explendid Video - Contact form');
$message = "Contact form\n\n";
$message .= "Name: ". $_POST['name'] . "\n";
$message .= "Phone: ". $_POST['phone'] . "\n";
$message .= "Email: ". $_POST['email'] . "\n";
$this->email->message($message);
$this->email->send();
Run Code Online (Sandbox Code Playgroud)
可能是什么原因,电子邮件实际上没有交付.
我真的在反复出现OOP /数据库概念.
请允许我解释伪PHP代码的问题.
假设您有一个"用户"类,它users在其构造函数中从表中加载其数据:
class User {
public $name;
public $height;
public function __construct($user_id) {
$result = Query the database where the `users` table has `user_id` of $user_id
$this->name= $result['name'];
$this->height = $result['height'];
}
}
Run Code Online (Sandbox Code Playgroud)
简单,棒极了.
现在,我们有一个"group"类,它从与groups表连接的groups_users表中加载其数据,并user从返回的user_ids 创建对象:
class Group {
public $type;
public $schedule;
public $users;
public function __construct($group_id) {
$result = Query the `groups` table, joining the `groups_users` table,
where `group_id` = $group_id
$this->type = $result['type'];
$this->schedule = …Run Code Online (Sandbox Code Playgroud) 我想在php中将xero api集成到公共应用程序中.我坚持使用oauth应用程序授权我从github下载代码 https://github.com/XeroAPI/XeroOAuth-PHP(在公共应用程序的xero api代码示例中找到)
我正在使用以下代码:
require('/../lib/XeroOAuth.php');
require('/../_config.php');
$useragent = "Xero-OAuth-PHP Public";
$signatures = array (
'consumer_key' => 'app_consumre_key',
'shared_secret' => 'app_secret_key',
'core_version' => '2.0'
);
$XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
include 'tests.php';
Run Code Online (Sandbox Code Playgroud)
我正在传递以下xml数据:
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>"; …Run Code Online (Sandbox Code Playgroud) 我试图使用DomPDF获取PDF,但我遇到了一个奇怪的问题.所有数据和其他东西都很好但是当它以PDF格式呈现时,表格的第一行总是不合时宜.首先,我可能是表格正在下一页导致风格脱离上下文但我试图将表限制为一页,并发现问题仍然存在.所以,每一页上的第一行表都很疯狂.以下是我的PDF代码和屏幕截图.
调节器
$dompdf = new DOMPDF();
$dompdf->load_html($listing);
$dompdf->set_paper('a4', 'landscape');
$dompdf->render();
$dompdf->stream("sample.pdf");
Run Code Online (Sandbox Code Playgroud)
视图
<table class="table table-bordered">
<tr>
<th width="150">Client </th>
<td>Client Name </td>
</tr>
<tr>
<th>Site </th>
<td><?php print $site->title; ?></td>
</tr>
<tr>
<th>Address </th>
<td>
<?php
print $site->unit.' '.
$site->street.' '.
$site->suburb.' '.
$site->state.' '.
$site->location;
?>
</td>
</tr>
<tr>
<th>Post Code </th>
<td><?php print $site->postcode; ?></td>
</tr>
<tr>
<th colspan="2"> Site Information</th>
</tr>
<tr>
<td colspan="2" height="150"> <?php print $site->site_information; ?></td>
</tr>
<tr>
<th colspan="2">Work Instruction</th>
</tr>
<tr>
<td …Run Code Online (Sandbox Code Playgroud) 我使用codeigniter
与ion_auth配置,以及MySQL作为后端,我的应用程序流畅运行,但有时/不是随机当我打电话add/update的功能,它会自动登录我出去.我正在研究它最近1个月但到目前为止找不到解决方案?我也改变了ion_auth配置文件中的设置.
$config['user_expire'] = 0;
Run Code Online (Sandbox Code Playgroud)
任何想法,解决这个问题?
请评论,以便我可以根据需要提供更多数据.
注意:我也检查过这个,但没有运气.
它在Windows命令提示符下显示" 'brew'未被识别为内部或外部命令 ".
我正在尝试从github安装codeigniter-reactjs-example,其中第一个命令是.如何运行此命令在Windows中安装该项目..?brew