Adding A New Page In CodeIgniter

2019-04-15 07:56发布

问题:

I apologize in advance for my ignorance of CodeIgniter and the MVC system.

I'm helping a family member with their business website and up until now I've been able to complete most of the required changes just by using logic but now I've hit a dead end. I don't plan to continue supporting them as I'm obviously no CodeIgniter expert. But I'm hoping to leave the website at least functional, so that they can start using it.

I simply want to create a new "page" within the website but it seems impossible. If I can achieve this I think I can figure everything else out on my own.

For example I currently have a "page" for Cancelled Jobs. It the navigation HTML it is linked to like this:

http://localhost/admin/modules/cancelled_jobs

and has a corresponding file here: admin/application/controllers/cancelled_jobs.php

which contains this php code:

class Cancelled_jobs extends CIID_Controller {


    public function __construct()

    {       

        parent::__construct();

        $this->set_table('job', 'Cancelled Job', 'Cancelled Jobs');

        $this->allow_delete = false;
        $this->allow_cancel = false;
        $this->allow_edit = false;
        $this->allow_reactivate = true;
        $this->allow_add = false;

        $this->overview
            ->add_item('Job No', 'active', 'job_id')
            ->add_item('Client', 'active|relationship', 'client.name')
            ->add_item('Name', 'active', 'name')
            ->add_item('Status', 'active|relationship', 'job_status.name')
            ->add_item('Assignee', 'active|relationship', 'team_member.name')
            ->add_item('Scheduled Date', 'active', 'scheduled_date')

            ->where("job.cancel_job = '1'")
            ->order_by('job.created_date DESC');

        $this->init();

    }


}

I would like to create a new "page" called Closed Jobs.

I've tried copying admin/application/controllers/cancelled_jobs.php and renaming it closed_jobs.php and changing the first line of code to read:

class Closed_jobs extends CIID_Controller {

I then add a link in the navigation HTML:

http://localhost/admin/modules/closed_jobs

However, when clicked, this only results in a "404 Page Not Found" error.

Can anyone point out what I'm missing in the process of creating a new page?

回答1:

Generally, CodeIgniter URLstructure is:

sitename.com/controller_name/function_name/parameter_1/parameter_2/parameter_3/

You can add as many parameters as you want.

To access

modules/closed_jobs:

Add a new function in the controller modules

function closed_jobs() {
  $this->load->view('closed_jobs');
}

And create a view closed_jobs.php

in application/views

Repeat the same for cancelled_jobs