在codeiginter中使用redirect()函数发布数据数组或单个变量字符串数据是否有办法或一些技巧?
我不知道我的逻辑是否不正确但我无法获得我的form_dropdown(下拉列表)列表以填充我的数据库中的数据.
我得到的错误是Undefined属性:stdClass :: $ name.
代码吼叫.
print_r($ appertisers)时$ appertisers中的My Array;
Array ( [0] => stdClass Object ( [product] => Marinated mixed olives ) [1] => stdClass Object ( [product] => Simons ) [2] => stdClass Object ( [product] => Test ) )
Run Code Online (Sandbox Code Playgroud)
视图
$array = array();
foreach($appertisers as $row ){
$array = $row->name;
}
echo form_dropdown('appetisers', $array);
?>
Run Code Online (Sandbox Code Playgroud)
模型
class Get_data extends CI_Model{
function getAppertisers(){
$query = $this->db->query("SELECT product FROM products WHERE cat = 1");
return $query->result();
}
}
Run Code Online (Sandbox Code Playgroud)
调节器 …
我有一个用户填充的codeigniter表单.在提交时,输入被发布到数组.然后,此数组将显示在作为变量加载的新视图中.
我的问题是,如果我因任何原因刷新视图,那些帖子就会丢失,新视图也无法显示变量.
如何将发布的数组存储为会话值,然后如何访问会话变量.
所以我的控制器是:
function new_blank_order_lines()
{
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom')
);
$this->load->view('sales/new_blank_order_lines',$data);
}
Run Code Online (Sandbox Code Playgroud)
在new_blank_order_lines我可以显示与变量echo $customer
现在,如果我刷新视图new_blank_order_lines,则重新加载视图并丢失post变量.所以我想将$ data数组存储为一个会话,因此即使在页面重新加载/刷新之后它也可用.
有什么建议?
我想的是:
function new_blank_order_lines()
{
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom')
);
$this->session->$data
$this->load->view('sales/new_blank_order_lines',$data);
}
Run Code Online (Sandbox Code Playgroud)
这显然不起作用?如果它确实有效,我如何回显变量的值?
一如既往地谢谢,
在发布之前,我在网上搜索了相关问题,但找不到任何相关问题的帮助.
我正在使用CodeIgniter下的Web应用程序.我正在使用KendoUI.KendoUi已安装.
问题是我想使用KendoUi网格,但该网格遵循json格式和其他像xml.
但问题是,我在kendoUi网站上看到的文档,据他们说,我需要有另一个数据源文件.其中应包括数据库的echo查询,该查询将用作网格的数据源.
但我想知道是否有可能在codeigniter中,如果kendoui网格直接从数据库加载数据而不是在ohter php文件上回显数据然后将其放在网格上.
当且仅当它不可能时,我应该采用什么方法为codeigniter mvc模式实现网格?我应该用我的目录中的数据名称创建另一个目录吗?或者我该怎么办..
真的需要你的所有指导.
KendoUi和codeigniter的新手.
根据文档,我尝试下面的代码来找到codeigniter中的数组大小
echo element('size', $get, NULL);
Run Code Online (Sandbox Code Playgroud)
但它最终显示以下错误
( ! ) Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\cinifb_ci\system\helpers\array_helper.php on line 46
Run Code Online (Sandbox Code Playgroud)
我试图将内容加载$get到另一个数组变量中,但它继续显示上述错误.
请建议我解决这个问题的替代方法.
我试过使用本机PHP解决方案
echo size_array($get);
Run Code Online (Sandbox Code Playgroud)
但它最终进入了
Fatal error: Call to undefined function size_array()
Run Code Online (Sandbox Code Playgroud)
这是否意味着我不应该在CodeIgniter中使用本机PHP函数
好的,我查看了其他每一个帖子,并完成了他们已经完成的工作以及手册中的内容,我无法想象我的生活.正在通过电子邮件将cron作业的结果发送到我的一封电子邮件中.它正在做的就是打印出布局的html标记...并打印基页内容......就像它没有注册任何东西一样.
php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats
Run Code Online (Sandbox Code Playgroud)
这是我的命令行..我尝试用用户/本地/ bin/php的东西替换php,但它没有用.问题是我有其他cron作业运行程序PHP代码,使用PHP路径/到/ cron.php工作FINE ...但它不适用于CI ..
我的控制器是Cron,我的方法是decrease_pets_stats ..
//decrease pets stats
public function decrease_pets_stats() {
$this->load->model('Cron_model', 'cron');
$this->cron->decrease_pets_stats();
echo 'Decreased pet stats';
}
Run Code Online (Sandbox Code Playgroud)
以下是该方法的逻辑:
//decrease pets stats
//runs every hour
public function decrease_pets_stats() {
$this->db->set('hunger', 'hunger - 5');
$this->db->set('happiness', 'happiness - 5');
$this->db->set('loyalty', 'loyalty - 5');
$this->db->update('user_creature');
}
Run Code Online (Sandbox Code Playgroud)
有谁知道它为什么只是打印布局标记?我的构造函数看起来像这样:
public function __construct() {
parent::__construct();
if( ! $this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->model('Cron_model', 'cron');
}
Run Code Online (Sandbox Code Playgroud)
我的父构造函数包含相当多的东西(加载帮助程序和库,以及如果用户登录,则会在每个页面上显示用户信息.
在打开控制器Cron类之前,这是否位于控制器的顶部是否重要?
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Run Code Online (Sandbox Code Playgroud) 这是我的控制器..
class Customer extends CI_controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Customer_model');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('address', 'Address', 'required');
$this->form_validation->set_rules('office_phone', 'Phonenumber', 'required');
$this->form_validation->set_rules('fax', 'Faxno.', 'required');
$this->form_validation->set_rules('email', 'Mailaddress', 'required');
$data = array(
'name' => $this->input->post('name'),
'address' => $this->input->post('address'),
'phoneno' => $this->input->post('office_phone'),
'fax' => $this->input->post('fax'),
'email' => $this->input->post('email')
);
if ($this->form_validation->run() === FALSE)
{
$this->load->helper('url');
$this->load->view('templates/header');
$this->load->view('master/customer',$data);
}
else
{
$this->Customer_model->register($data);
$this->load->library('session');
//$this->session->set_flashdata('message', 'New Contact has been added');
//redirect(current_url());
$this->load->helper('url');
$this->load->view('templates/header');
$this->load->view('templates/success');
}
$this->load->library('pagination');
$this->load->library('table');
// …Run Code Online (Sandbox Code Playgroud) 我正在使用Codeigniter进行项目.
这是我的购物车的样子
No.1 | Appple |数量-2
No.2 |橙色|数量-3
No.3 |橙色|数量-3
通常如果我使用"$ this-> cart-> total_items();" .我会得到2 + 3 + 3 = 8.但是,我只想要rowcount(参见有三行).我想要'3'.有没有像'$ this-> cart-> rowcount()'这样的东西?
我是php codeigniter会话的新手.我有关于我的网站上的会话过期的问题.我正在使用ajax coll在我们的网站页面上添加广告div,并添加到购物车功能以在同一页面上添加多个产品.但由于会议在审批后过期,我的购物车添加的产品是空的.4-5分钟.关于这个问题,我做了很多研究.我认为我的网站会话已过期,因为同时更新了ajax并更新了会话ID.但我不确定.
我已配置config.php文件,如 -
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_encrypt_cookie']= FALSE;
$config['sess_use_database']= TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent']= TRUE;
$config['sess_time_to_update'] = 300;
Run Code Online (Sandbox Code Playgroud)
我还创建了表(ci_sessions).
请给我一个解决方案来解决这个问题.
谢谢.
我会尽量简明扼要,我是bootstrap和高级javascript的新手,基本上我已经使用bootstrap模式在用户面前加载一个表单来收集和保存数据库中的数据.我的问题是你将如何使用ajax,因为我还有其他模式,它将有不同的形式,我不想一次又一次地处理整个页面.PS我在codeigniter中创建此应用程序
这是模态内部的形式
<section id="launch" class="modal hide fade" style="width: 800px; left: 500px;">
<header class="modal-header" style="height: 7px; background: none repeat scroll 0% 0% rgb(87, 164, 210);">
<h4 style="margin-bottom: 0px; margin-top: -5px; text-align: center; color: white;">Unit Details</h4>
<button type="button" class="close" data-dismiss="modal" style="margin-top: -20px;">×</button>
</header>
<?php echo form_open('setupnewblock/registerNewBlock'); ?>
<div class="modal-body" style="padding-top: 0px; padding-left: 0px; " >
<div style="position: relative; left: 43px; margin-top: 41px; margin-left: 0px;">
<span>Address 1</span>
<input type="text" placeHolder="" name="address1" style="width: 219px; height: 17px; margin-left: 20px; margin-top: 3px;" value="<?php echo set_value('address1'); ?>"/> …Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×5
session ×2
ajax ×1
arrays ×1
cron ×1
html ×1
javascript ×1
jquery ×1
kendo-grid ×1
kendo-ui ×1
post ×1
redirect ×1
undefined ×1
variables ×1