English 中文(简体)
• 帮助我 n子与《国际公认准则》合作
原标题:Getting my nav menu to work with CodeIgniter

Basically I have two controllers using CodeIgniter for a simple blog for a project at school. One is Home which is the login page. The other is Member for when they are signed in. in this member controller I am creating functions for add_post(), view_users_posts(), etc. Member.php

class Member extends CI_Controller{

function __construct(){
    parent::__construct();
    $is_logged_in = $this->session->userdata( is_logged_in );
    if (!isset($is_logged_in) || $is_logged_in !== true) {
        redirect( home );
    }
}

public function index() {
    $this->load->library( pagination );

    $config[ base_url ] = base_url() .  index.php/member/index/ ;
    $config[ total_rows ] = $this->db->get( posts )->num_rows();
    $config[ per_page ] = 5;
    $config[ num_links ] = 20;

    $this->pagination->initialize($config);

    $data[ posts ] = $this->posts_model->get_all_posts($config[ per_page ], $this->uri->segment(3));
    $this->load->view( member_view , $data);
}

public function add_post() {
    $this->load->view( add_post_view );
}

My member view has a nav menu with links to these functions like so: member_view.php

      <li><a href="member">Home</a></li>
      <li><a href="member/add_post">Add Post</a></li>
      <li><a href="member/view_users_posts">My Posts</a></li>
      <li><a href="member/reset_pass">Reset Password</a></li>
      <li><a href="member/logout">Logout</a></li>

我在知道什么是成文时,就没有了。 基本上,如果用户点击添加员额,就应当提到职能增加——控制人员中将装上“附加”的词句? 或者,它是否直接给一位称为“Add”的新控制员,该员额将装上观点?

我的理由是,如果我点击增设员额,那么我就把这个职位带给各位成员/代表,但当我点回家时,我再找成员/成员,然后再加一个职位。

我希望这一点是有意义的,我完全是损失了。 感谢任何帮助!

最佳回答

页: 1

页: 1

之后,您的法典将出台。

<li><a href="<?php echo base_url( member/add_post );?>">Add Post</a></li>

Do the same for other items.

<>说明: conf中弹片。 否则就列入<编码>基准_url(/member/add_post >。

http://codeigniter.com/user_guide/helpers/url_helper.html>rel=“nofollow”

问题回答

You are on the right track. For the menu items you have, you would have to complete these controller functions:

class Member extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $is_logged_in = $this->session->userdata( is_logged_in );
        if (!isset($is_logged_in) || $is_logged_in !== true) {
            redirect( home );
    }

    function add_post()
    {
        // for example:
        $this->load->view( header );  // standard header and menu view
        $this->load->view( add_post );  // input form view
        $this->load->view( footer );   // standard footer, adverts, etc.
    }

    function view_users_posts()
    {
        $data [ posts ] = $this->model->get_all_posts( ...(etc)... );
        $this->load->view( header );  // standard header and menu view
        $this->load->view( view_users_posts , $data);
        $this->load->view( footer );   // standard footer, adverts, etc.
    }

    function reset_pass()
    {
        ...
    }

    function logout()
    {
        ...
    }
}

第一个新职能参考文件views/header.php,views/add_post.php>/code>和views/footer.php。 其他“成员”职能可能也应装上头盔和脚步(连续的现场视线),但装上不同的功能体,可能称为与功能非常相似的东西。

我已经假定了<代码>view_users_posts()进入一些新的模型功能,以检索这些员额,并顺从适当格式。 注:view/view_users_posts.php 应采用我上述方式查阅<代码>的贴现/编码>。

一段时间前,我也存在同样的问题。 我的解决方案是,它为达到指数.php的道路奠定了基础。 例如

$config[ base_url ] = "http://localhost/codeigniter/index.php/"

这样,你就能够像现在这样使用。

<a href="<?php echo base_url() ?>Controller/Action/Param1/Param2">Link Text</a>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签