dorv56831 2013-01-15 16:35
浏览 62
已采纳

使用codeIgniter组织Web应用程序

I have a problem with the organization of views on CodeIgniter.

Project: Create a simple web application that permits to manage a library(bookcase).

I created 3 models : Member, Categories, Books with their respective controllers.

I implemented the Member model with its controller.

In the member_controller we have:

public function login(){

$this->load->helper('form');
$this->load->helper('email');
$this->load->library('form_validation');

$mail = $this->input->post('mail');
$pass = $this->input->post('pass');

$data['mail'] = $mail;
$data['pass'] = $pass;


$this->form_validation->set_rules('mail', 'mail', 'required');
$this->form_validation->set_rules('pass', 'pass', 'required');

if ($this->form_validation->run() === TRUE)
{

$result=$this->membre_model->login($mail,$pass);

if($result==TRUE){

$this->load->view('templates/header.php');
$this->load->view('membre/logged',$data);
$this->load->view('templates/footer.php');


}

Once user is logged, I want to show all existing categories he previously created(so get them from the database).

  • How can I do that?
  • Do I have to call a function of the category controller in the login function of the member controller?
  • Do I have to load the category view from the Login function?
  • Do I have to build the site from just one controller(the member controller)?
  • How to build the webapp with differents views of differents controllers?

Finally, the thing I don't get is how the different controller communicate between them.

  • 写回答

2条回答 默认 最新

  • dpftppc9674 2013-01-15 17:04
    关注

    How can I do that?

    You would have to add an exception when loading each page that will redirect user based on their login status. In other words, if user is logged in, bring him to the application. If user does not exist, redirect him to the registration page.

    This can be done by verifying if the user is logged in based on stored session values. If this session is stored than you can let the user view the page. Here is a great tutorial explaning a simple Login system for Codeigniter.

    http://www.codefactorycr.com/login-with-codeigniter-php.html

    In my opinion, I usually use an Authentication library to simplify the Login system for my application. I would use Ion Auth, it has a great documentation explaning all the functions you can use.

    Do I have to call a function of the category controller in the login function of the member controller?

    You can simply use the category controller as you would normally. You would change the pages information or redirect the user out based on the session information stored in their browser.

    Do I have to load the category view from the Login function?

    You would load the category view from the category controller. The login controller would redirect the the user to the category controller after the login is performed.

    Do I have to build the site from just one controller(the member controller)?

    No, you can have as many controllers as you like.

    How to build the webapp with differents views of differents controllers?

    A controller would represent a section of your site. This controller would load multiple views for different things. Here is a great little tutorial explaning the MVC worklow. This will help you understand the process.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测