dql7588 2014-10-31 07:29
浏览 15
已采纳

CodeIgniter - 博客页面中的登录表单[关闭]

I am new in using codeIgniter, I am so sorry if i am asking a stupid easy question. I'm making a simple news website for my class project with the login form for the administrator in the same page (homepage) as the news posts (like 2 frames in html). Is it possible to load some functions and classes from different controllers and models in one view)? From many example that i learned, it always has only login page without other column with different controllers. And i tried to do what I think is true but everything i've tried just didn't work. If anyone know the solutions, explanations, or similar examples for this problem, please share me the explanation in any form (video, web link, document, anything). Thanks before..

  • 写回答

1条回答 默认 最新

  • dsiftnc99059 2014-10-31 07:38
    关注

    If you need functions between controllers, you should define it as a CI model, or at least a helper. Controllers are simply interfaces between models and views. You need to create a login model, with commonly these functions:

    $user -> getUserInfo()
    $user -> login()
    $user -> logout()
    $user -> register()
    $user -> userExists()
    $user -> isLoggedIn()
    ..
    

    and then call these inside your controllers.

    Edit for comment: Yes you can include views inside your views, and this is like common usage.


    First method: directly in the controller

    $this->load->view("header");
    $this->load->view("subpage");
    $this->load->view("footer");
    

    and the result will be having three views appended together. Source: https://ellislab.com/codeigniter/user-guide/general/views.html


    Second method: in the controller assigning to variables

    $data = array();
    $data["header"] = $this->load->view("header", NULL, TRUE);
    $data["footer"] = $this->load->view("footer", NULL, TRUE);
    $this->load->view("subpage", $data);
    

    and in subpage view:

    <?php echo $header;?>
    (Sub page view data)
    <?php echo $footer;?>
    

    Third method: directly in the subpage view

    <?php $this->load->view('header');?>
    (subpage content)
    <?php $this->load->view('footer');?> 
    

    Sources for second and third: https://ellislab.com/forums/viewthread/88335/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备