应该何时制作新型号或控制器?是否只有控制器与相应的视图1对1一起使用,并且控制器和模型是这样的?或者,控制器的功能是否与任何特定视图无关?例如,投票,如果所有投票代码都在投票控制器中,或者在具有使用投票的观点的控制器之间传播.似乎投票控制员可能是最好的.
嗨我正在使用codeigniter,在我的控制器构造函数中,有时我$this有时使用$this->ci
在两个构造函数中,我使用这样的
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->library('form_validation');
$this->ci->load->library('catalog/CatalogManager');
}
function __construct()
{
parent::__construct ();
$this->ci = & get_instance ();
$this->load->library ( 'auth_lib' );
$this->load->library ( 'session' );
}
Run Code Online (Sandbox Code Playgroud)
当传递数据以查看我使用
$this->ci->data和$this->data在上述两种情况.
既没有错误,但我很困惑,正确的用途是什么.
请帮忙...........
我想知道是否有办法处理mysql错误并配置ci在主服务器关闭(无法连接)的情况下切换到辅助数据库服务器?
假设我有一个有趣的视频网站,向用户显示有趣的视频.在每个视频下面,我想根据视频的时间戳和当前时间有一个声明"5秒前","31分钟前","昨天","2天前".
我的时间戳格式为:2011-10-17 07:08:00.
我对日期不太满意,但我猜我需要找到2个日期/时间之间的差异,然后决定它是在0秒和60秒之间以秒显示,还是在60秒和3600秒之间显示在几分钟之间,或3600sec&3600x24sec以小时为单位显示,3600x24sec&3600x24x2sec之间显示昨天,等等......我相信我应该使用strtotime(),但我不能似乎找到当前时间,我发现使用这些解决方案,new date()这确实似乎没有工作!
我怎样才能做到这一点?
顺便问一下,当我插入2011-10-17, 7:08PM EDTMySQL时间戳列时,它被转换2011-10-17 07:08:00为AM.如何将其存储在正确的AM/PM中?
有没有办法让base_url()我的控制器设置?
或者我可以设置我的base_url Dynamic吗?
我怎么能做到这一点?
mysql查询后如何接收索引数组?还是有什么方法可以转换$this->db->get()成mysql资源?还是将关联数组转换为索引?
当我尝试在CodeIgniter中运行以下应用程序时,我收到以下错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/blog.php
Line Number: 1
Run Code Online (Sandbox Code Playgroud)
我一直试图弄清楚将近一个小时,我无法让它工作.我的观点如下:
<?php foreach($data->result() as $row): ?>
<h1><?php echo $row->title; ?></h1>
<p><?php echo $row->post; ?></p>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样:
<?php
class Blog extends CI_Controller {
public function index()
{
$this->load->database();
$data = $this->db->get('posts');
$this->load->helper('url');
$this->load->view('header');
$this->load->view('blog', $data);
$this->load->view('footer');
}
}
Run Code Online (Sandbox Code Playgroud)
有人知道怎么修这个东西吗?
我想知道Code Igniter是否具有与我构建的小框架相当的东西,以及它可能被称为什么.我构建了一个小框架,为每个mysql数据库表创建一个列表视图和编辑视图.下面显示了如何设置CMS来操作数据库表的代码示例:
// CODE FOR LIST VIEW - http://mysite.com/admin/user.php
// This code will output an html table of records from db table t_user.
// The html table will have controls that allow user to search, delete, and paginate
// You can click on each record to edit the record
<?php
include('class/framework.php');
$template = new ListView();
$template->data_object = new DB($mysql_table_name = 't_user');
$template->setCol($col = 'user_name', $label = 'User Name');
$template->setCol($col = 'email', $label = 'Email');
$template->setCol($col = 'last_login', $label = 'Last …Run Code Online (Sandbox Code Playgroud) 大家好,我对一个看似简单的表连接感到生气,但我不知道出了什么问题,因为我不知道查询是什么.有没有办法调试Active Records?我在这里找到了一个,但是如何访问连接对象?
真正的问题是我试图提取用户所关联的所有项目(关系船在一个木匠表中)
项目表 - > user_projects表 - >用户表
Project::find('all', array(
'select' => 'user_projects.id, title, description, last_update',
'conditions' => array('user_projects.user_id = ?', $user_id),
'joins' => 'LEFT JOIN user_projects ON projects.id = user_project.project_id'
));
Run Code Online (Sandbox Code Playgroud) 可能重复:
CodeIgniter禁止关键字符
当我检查所有复选框(下面的代码)时,它给了我这个错误:
不允许的关键字符
这是我的HTML:
<label>Stability Control </label><input type="checkbox" class="largercheckbox" name="checkBox[Stability-Control]"></input><br/>
<label>Xenon Headlamps</label><input type="checkbox" class="largercheckbox" name="checkBox[Xenon-Headlamps]"></input><br/>
Run Code Online (Sandbox Code Playgroud)
这有什么问题?我认为我的配置文件允许这些字符:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×8
mysql ×2
activerecord ×1
architecture ×1
arrays ×1
crud ×1
date ×1
jquery ×1
variables ×1