• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing GET value show error

#1
hi , sorry for english :

 i make a script to simulate a agenda , passing a data to a controller agenda/visualizza_settimana/day_of_week as (Y:m:d) show the week . Now i want search a data by a field type date , select a data and in my controller have 

$this->load->view('agenda/visualizza_settimana/'.$uk_date)

 but have this error : Unable to load the requested file: agenda/visualizza_settimana/2017-09-13.php , if i insert 2017-09-13 as parameter manually it work properly , why ?

Work properly if i use redirect instead $this->load->view too.
Reply

#2
A redirect loads a controller path and file, not a view file. A load->view loads a view file, not a controller, so you cannot pass a date to a view file in the url like that.

Your load command is looking for a file called agenda/visualizza_settimana/2017-09-13.php in your views folder. I am guessing that you need to load your view something like agenda/visualizza_settimana/day_view (no .php required) from your controller class called Agenda, with a method called visualizza_settimana which is expecting a variable like $date, that you use to collect the data for the day_view and then load the day_view.

Agenda controller:
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
Agenda extends CI_Controller {

 
   public function visualizza_settimana($date)
 
   {
 
           // used date to get data you need to show
 
          $data = array('name'=>'Paul');

 
           // load your view
 
           $this->load->view('agenda/day_view'$data);
 
   }



day_view view file in a folder called 'agenda' inside the views folder, called day_view.php
PHP Code:
   <h1>Day View</h1>
 
   <p><?php echo $name?></p> 
Just html with the data you sent to the view displayed however you want.


Hope that helps, it seems complicated when you write it but it really is not.

Paul.
Reply

#3
(09-26-2017, 11:19 AM)PaulD Wrote: A redirect loads a controller path and file, not a view file. A load->view loads a view file, not a controller, so you cannot pass a date to a view file in the url like that.

Your load command is looking for a file called agenda/visualizza_settimana/2017-09-13.php in your views folder. I am guessing that you need to load your view something like agenda/visualizza_settimana/day_view (no .php required) from your controller class called Agenda, with a method called visualizza_settimana which is expecting a variable like $date, that you use to collect the data for the day_view and then load the day_view.

Agenda controller:
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
Agenda extends CI_Controller {

 
   public function visualizza_settimana($date)
 
   {
 
           // used date to get data you need to show
 
          $data = array('name'=>'Paul');

 
           // load your view
 
           $this->load->view('agenda/day_view'$data);
 
   }



day_view view file in a folder called 'agenda' inside the views folder, called day_view.php
PHP Code:
   <h1>Day View</h1>
 
   <p><?php echo $name?></p> 
Just html with the data you sent to the view displayed however you want.


Hope that helps, it seems complicated when you write it but it really is not.

Paul.

No , i dont understand , i have in another project the same problem :

I have a controller Documentazione this is a function :

Code:
  public function crea_documentazione_seconda($id) {

        $data = [];

        $record = $this->documentazione_model
                ->get_Documentazione($id);
       


        $data['res'] = $record;

        $this->form_validation->set_rules('id', 'Id', "required|trim|min_length[0]|max_length[10]", array('min_length' => 'Lunghezza minima id 0 caratteri', 'max_length' => 'Lunghezza massima id 10 caratteri', 'required' => 'id obbligatorio'));
        $this->form_validation->set_rules('data_consegna_dispositivo', 'Data_consegna_dispositivo', "trim|min_length[0]|max_length[10]", array('min_length' => 'Lunghezza minima data_consegna_dispositivo 0 caratteri', 'max_length' => 'Lunghezza massima data_consegna_dispositivo 10 caratteri'));
        $this->form_validation->set_rules('luogo_consegna', 'Luogo_consegna', "trim|min_length[0]|max_length[100]", array('min_length' => 'Lunghezza minima luogo_consegna 0 caratteri', 'max_length' => 'Lunghezza massima luogo_consegna 100 caratteri'));

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



            $res = $this->documentazione_model
                    ->editDocumentazioneSeconda(
                            $this->input->post('id'),          
                            $this->input->post('data_consegna_dispositivo'), 
                            $this->input->post('luogo_consegna')
            );

            if ($res) {

                $this->redirect('documentazione/crea_documentazione_terza/'.$record->id);

             
            } else {

    $this->load->view('templates/header', $data);
                   $this->load->view('templates/menu', $data);
                 $this->load->view('documentazione/crea_documentazione_seconda/'


               $this->load->view('templates/footer', $data);
            }
        } else {

            $this->load->view('templates/header', $data);
            $this->load->view('templates/menu', $data);

            $this->load->view('documentazione/crea_documentazione_seconda', $data);


            $this->load->view('templates/footer', $data);
        }
        

    }

I have also a view called : crea_documentazione_seconda.php in folder documentazione

It need a GET  value   because if form_validation->run()=FALSE i have this problem :

Message: Missing argument 1 for Documentazione::crea_documentazione_seconda()


How can i solve ?
Reply

#4
(10-01-2017, 03:37 AM)pippuccio76 Wrote:
Code:
$this->load->view('documentazione/crea_documentazione_seconda/'

this line of code has missing ); on the end. I presume this is a typo in posting the question.

That message is just telling you that you are calling a controller with a missing argument.

You are calling somewhere this function:
PHP Code:
crea_documentazione_seconda($id
Without an id.

I do not know where you are doing this.

If I have misunderstood your problem I apologise in advance,

Paul

PS I find it useful to call my views and controllers things like:
Dashboard.php (controller)
dashboard_view.php (view file)
Dashboard_model.php (model file)
Dashboard_library.php (library file)
etc.
Reply

#5
(10-01-2017, 08:14 AM)PaulD Wrote:
(10-01-2017, 03:37 AM)pippuccio76 Wrote:
Code:
$this->load->view('documentazione/crea_documentazione_seconda/'

this line of code has missing ); on the end. I presume this is a typo in posting the question.

That message is just telling you that you are calling a controller with a missing argument.

You are calling somewhere this function:
PHP Code:
    crea_documentazione_seconda($id
Without an id.

I do not know where you are doing this.

If I have misunderstood your problem I apologise in advance,

Paul

PS I find it useful to call my views and controllers things like:
Dashboard.php (controller)
dashboard_view.php (view file)
Dashboard_model.php (model file)
Dashboard_library.php (library file)
etc.
I see and know the error...

I have this sistem because i have a list with all the record and have for every record a button :

<a href='<?= base_url() ?>index.php/documentazione/crea_documentazione_seconda/<?= $row->id ?>' class='btn btn-primary btn-xs'><i class='fa fa-pencil'></i> Modifica Documentazione </a>
(after other value in datatable)

In this way when i push the button i can modify  the record...



There's a way to do this in another way
Reply

#6
That seems a fair approach but you could use site_url instead, just a bit cleaner.

PHP Code:
<a href='<?php echo site_url('documentazione/crea_documentazione_seconda/'.$row->id); ?>' class='btn btn-primary btn-xs'

If pressing that button is causing the missing argument, then just take a look at the html generated for the button and check the id is being found and is populated as you expected.

Other than that I cannot debug your code, sorry.

Paul

PS Looking at your first post again, when you load a view file you are just loading a file, and sending it some data. You are not loading a controller into the view.
PHP Code:
$this->load->view('my_view_file'$page_data); 
If you use a variable in the view file name, you have to be careful that the file actually exists before you load it using file_exists.
Reply

#7
(10-01-2017, 08:46 AM)PaulD Wrote: That seems a fair approach but you could use site_url instead, just a bit cleaner.

PHP Code:
<a href='<?php echo site_url('documentazione/crea_documentazione_seconda/'.$row->id); ?>' class='btn btn-primary btn-xs'

If pressing that button is causing the missing argument, then just take a look at the html generated for the button and check the id is being found and is populated as you expected.

Other than that I cannot debug your code, sorry.

Paul

No with a pression of button the sistem work fine , the problem is when i submit the form without passing the form_validation and an argoment missing when loading  $this->load->view('documentazione/crea_documentazione_seconda')
Reply

#8
There must be something else going wrong with your code. A missing argument error is not a message you get with a view file, but with a controller. With a view file any missing data is displayed in the html as a php error.
Reply

#9
(10-01-2017, 08:57 AM)PaulD Wrote: There must be something else going wrong with your code. A missing argument error is not a message you get with a view file, but with a controller. With a view file any missing data is displayed in the html as a php error.

is simple , the method want an argument , when the form_validation is false this is the code :

Code:
               $this->load->view('templates/header', $data);
               $this->load->view('templates/menu', $data);

               $this->load->view('documentazione/crea_documentazione_seconda', $data);


               $this->load->view('templates/footer', $data);

and the $id is not isset , but i want know if ther's an alternative way to do this....
Reply

#10
Quote:[18:17:59] <Paradinight> form_open('documentazione/crea_documentazione_seconda/'.$res->id, $attributes);
[18:18:14] <Paradinight> you miss the id part
[18:19:50] <pippuccio76> tanks it work
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.