我目前正在使用Codeigniter框架.在下面的代码中,我想获得一个Animal_model对象,而不是一个stdClassObject.
<?php
class Animal_model extends CI_Model{
var $idanimal;
var $name;
public static $table = 'animals';
function __construct() {
parent::__construct();
}
function getone(self $animal){
$query = $this->db->get_where(self::$table, array('id_animal' => $animal->idanimal));
if($query == FALSE){
return FALSE;
}else{
return $query->row(); // How to get an Animal_model object here?
}
}
}
$lion = new Animal_model();
$lion->idanimal = 25;
var_dump($lion); // It says "object(Animal_model)".
$lion = $lion->getone($lion);
var_dump($lion); // Now it says "object(stdClass)".
?>
Run Code Online (Sandbox Code Playgroud)
如何转换$query->row()为Animal_model对象?
我在Codeigniter中使用oci8作为我的数据库驱动程序.使用以下调用存储过程的代码时给出了错误:
$this->db->call_function('update_letter_body', $body_letter, $insert_id);
Error : This feature is not available for the database you are using.
Run Code Online (Sandbox Code Playgroud)
应该怎么做才能使这项工作?
我试图设置一个超过4000个字符的值,这似乎不能直接查询,似乎codeigniter不支持调用oracle的函数.有什么建议 ?
我使用CI创建了一个表单,并有一个原生的form_validation()库来验证每个字段输入,我使用jQuery post来回调输入以检查每个字段是否有效,如果我希望每个错误填充到每个字段form_error()旁边场而不是validation_errors()?
请参考以下内容:
视图:
<script>
$("#btnregister").click(function() {
var parameters = $("#reg_form").serialize();
$.post(baseurl+'pages/registration', parameters, function(data) {
if(data == "ok") {
//show success message
}else{
$("#error").html(data);
}
}, "html");
});
</script>
<div id="error"></div>
<form id="reg_form" method="post">
<p>
<label for="reg_username">Username</label><br />
<input type="text" id="reg_username" name="reg_username" value="<?php echo set_value('reg_username'); ?>">
<?php echo form_error('reg_username'); ?>
</p>
<p>
<label for="reg_email">Email</label><br />
<input type="text" id="reg_email" name="reg_email" value="<?php echo set_value('reg_email'); ?>">
<?php echo form_error('reg_email'); ?>
</p>
<p><input type="button" id="btnregister" value="Register"></p>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
public …Run Code Online (Sandbox Code Playgroud) 我打赌它最终会变得简单......但是我可以用它来发现它.
问题:
当我尝试获取特定本地URL的内容时file_get_contents(),它会以空字符串''(长度= 0)返回.
我尝试过的:
$url = 'http://localhost/bbq/index.php/company/get/id/2131/return/json';
$results = file_get_contents($url);
echo'<pre>Results:<br />',var_export($results),'</pre>';
Run Code Online (Sandbox Code Playgroud)
直接访问时http://localhost/bbq/index.php/company/get/id/2131/return/json,一切都很美妙:{"id":"2131","value":"Acme Anvil Corp."}
为了检查自己,我尝试了$url = 'http://www.google.com',它按预期工作,然后我尝试了一个单独的本地uri,http://localhost/?phpinfo=1它也工作得很好.
问题:
我错过了什么?
[附加信息]
allow_url_fopen开启
我可能刚刚发现了一些东西.
作为CODEIGNITER项目中的安全措施,控制器脚本的第一行具有:
if ( !defined('BASEPATH')) exit('No direct script access allowed');
Run Code Online (Sandbox Code Playgroud)
评论它没有提供任何改进,但我认为值得一提.
此外,这是HTTP响应标头的转储.也许有人可以看到那里的东西.这对我来说似乎很直接,但我真的不知道我应该寻找什么.
array (size=13)
0 => string 'HTTP/1.1 200 OK' (length=15)
1 => string 'Date: Thu, 27 Dec 2012 19:58:47 GMT' (length=35)
2 => string 'Server: Apache/2.4.2 (Win64) PHP/5.4.3' …Run Code Online (Sandbox Code Playgroud) 在登录后的codeigniter中,我将所有数据存储到会话中并重定向到论坛控制器.但我失去了论坛控制器中的所有价值观.
当我尝试从会话中减少一些值后,它完美地工作.
现在我的问题是 - 为什么会这样?在codeIgniter中是否存在会话中存储的值的上限?
即使我尝试搜索我发现像
redirect('forum', 'refresh');
Run Code Online (Sandbox Code Playgroud)
但它没有用.我的项目已经开发了一半,所以我不能使用codeignter的"PHP Native Session class".
您好:我需要在登录页面上实现忘记密码.在这里,我解释了到目前为止我所拥有的
email_exists()将验证电子邮件.如果是这样,send_email()使用$temp_pass密钥和链接.数据库将存储$ temp_pass以进行进一步的操作和验证.$temp_pass给函数reset_password.$temp_pass数据库.如果是这样,加载视图以输入新密码 - 这就是我被卡住的地方,因为表单指向一个无法识别的控制器$temp_pass因此无法重置密码.如何检索与正确用户关联的新密码并重置密码?
代码如下:
public function recover(){
//Loads the view for the recover password process.
$this->load->view('recover');
}
public function recover_password(){
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|callback_validate_credentials');
//check if email is in the database
$this->load->model('model_users');
if($this->model_users->email_exists()){
//$them_pass is the varible to be sent to the user's email
$temp_pass = md5(uniqid());
//send email with #temp_pass as a link
$this->load->library('email', array('mailtype'=>'html'));
$this->email->from('user@yahoo.com', "Site");
$this->email->to($this->input->post('email'));
$this->email->subject("Reset your …Run Code Online (Sandbox Code Playgroud) 我正在开发一个包含两个组件的项目:
1)一个是CodeIgniter框架,我将在其中构建所有自定义代码.
2)另一个是亚马逊用于MWS API的PHP SDK库.
问题是,我的CodeIgniter代码和亚马逊的SDK都需要自己的autoload().
亚马逊的SDK还进一步分为3-4个组件,每个组件都有自己的自动加载功能,所以如果你想在同一个会话中使用产品的SDK,然后使用Reports SDK,你会遇到已定义的自动加载功能.
出于这个原因,我正在考虑建立一个Web服务系统,用于我自己的代码和Amazon的SDK文件之间的通信,即使它们位于同一台服务器上,但至少可以避免命名冲突.即我将向CodeIgniter外部的文件发送HTTP请求,该文件将处理Amazon的SDK,并以JSON或XML返回响应.
我不认为命名空间是一个选项,因为我不想浏览SDK中的每个文件/类并添加命名空间语句.
我的问题是,我应该注意这个方法有任何性能问题吗?除了名称空间之外,还有什么方法可以避免这种方法吗?
当CSRF令牌过期时,我不喜欢CI在默认情况下的行为方式.例如,当用户长时间显示登录表单并最终提交时,会出现带有错误消息的丑陋空白页面.
我想办法绕过这个,有人告诉我扩展Security类,并覆盖它的csrf_show_error()方法,如下所示:
class MY_Security extends CI_Security {
public function __construct()
{
parent::__construct();
}
public function csrf_show_error()
{
// comment out the default action
// show_error('The action you have requested is not allowed.');
// add redirect actions here
// I'd like to use some helper function here like redirect()
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我不能,或者我不知道如何从这里访问库和帮助程序,以便执行重定向.我不能在这里使用get_instance()函数,因为我收到错误.那么,我还能做些什么呢?或者还有其他更好的选择来阻止显示此错误页面吗?
使用codeigniter活动记录语法将数据从一个表插入另一个表的语法是什么?我尝试了通常的mysqli查询并且它可以工作,但我想使用CodeIgniter Active Record语法来保持一致性.
我尝试使用这些CodeIgniter Active Record查询,但仍然没有运气:
function insert_into()
{
$this->db->insert('table1');
$this->db->set('to_column');
$this->db->select('from_column');
$this->db->from('table2');
}
Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×7
amazon-mws ×1
architecture ×1
csrf ×1
httpresponse ×1
mysql ×1
object ×1
oracle ×1
passwords ×1
session ×1
sql ×1
stdclass ×1
validation ×1