3

私はコードイグナイターが初めてです。異なるページに複数のビューを表示したい。編集ボタンを作成するページを作成します。編集ボタンをクリックすると、別のページにリダイレクトされます。どうやってやるの?

これが私のコードです:

class Edit extends CI_Controller
{
    function __construct()
    {
            parent::__construct();
    }
    function edit()
    {
        $this->load->helper('url');
        if($this->input->post('edit') == True)
        {
            redirect('edit');
        }
    }
}
4

2 に答える 2

1

ビュー1:(リンクが存在する場所)

<?php echo anchor('Edit/edit', 'Edit Value'); // Here Edit is your controller and edit is the function name. ?>

そして、編集コントローラーで次のように変更します。

class Edit extends CI_Controller
{
    function __construct()
    {
            parent::__construct();
    }

    function edit()
    {
        $this->load->helper('url');
        if($this->input->post('edit') == True)
        {
            //redirect('edit'); //Do not use this as this line will call the same function again.
            $this->load->view('edit_view'); // where edit_view.php is present in your views directory. 
        }
    }
}

お役に立てれば。

于 2013-02-09T07:06:22.523 に答える
1

ボタンが表示されます。これは、表示中のボタンをクリックすると、他のページ (view ) にリダイレクトする必要があることを意味します。

ビューでこれをアンカーとして使用します。

 <?php echo anchor('controller_name/function_name', 'acnchor_name'); ?>

 <?php echo anchor('Edit/edit', 'edit'); ?>

edit は function と view の名前でなければなりません。

これで、クリックするとビューにリンクが表示され、編集ビューにリダイレクトされます。

希望はあなたを助ける!

于 2013-02-09T06:51:24.183 に答える