问题描述
|
我有一个简单的逻辑问题。我开始使用CodeIgniter,现在我了解Controller的概念。例如,该视图仅用于生成内容(而不是处理前的数据),控制器用于获取需要查看的所有信息。精细。
我的问题是:我有一个在iframe中称为“ 0”的民意调查,我想在其他时候将其打印在另一个控制器上。这条路是
Poll::index(1)
的亲戚(从逻辑上讲),我在Content::index()
上。
我在CI UserGuide上找不到类似情况的解释。
我怎样做?
谢谢。
编辑:我将做一个示例代码:
class Blog extends CI_Controller {
function index(){
// Do some prints
// Executes Poll::index(1),but store on some string
// Do some prints
}
}
class Poll extends CI_Controller {
function index($id){
// Do some prints
}
}
这个想法是:/poll/1
起作用,而ѭ5(也起作用(但是此秒将显示更多内容(带有民意测验))。
解决方法
有趣的是,我认为使用ob_start()可能对您有用,如果是我,我更愿意使用ajax调用来显示民意调查数据
这是代码。
class Blog extends CI_Controller {
function index(){
// Do some prints
// Executes Poll::index(1),but store on some string
ob_start();
Poll::index(1)
// You can now use this $output value to display or store in db or store in session,// but remember CI session can only hold upto certain length as it uses cookie
$output = ob_get_contents();
ob_end_clean();
// Do some prints
}
}
class Poll extends CI_Controller {
function index($id){
// Do some prints
}
}
, 我最喜欢的一种方法是将其中一种用作超类,以便Poll类扩展博客。这使您的民意测验可以利用您的博客方法。然后,您可以使用任何父方法并在所需的类#方法中加载适当的视图。