Welcome Guest, Not a member yet? Register   Sign In
Rather Newish to OOP, Controller question
#1

So I have something working how I wish it to but I am not sure it is the best way to do it. Essentially, I have a controller called PROJECT.php and two methods inside that controller, JOIN($project_id) and ENTER($project_id).

The join() is simple and queries information about the PROJECT from the database and sends it to the join.php view.

The join.php view has a simple form:

PHP Code:
               <?php
                $attributes 
= array('class' => 'form-horizontal');

 
               echo form_open('project/enter/' $pool['pool_id'], $attributes);
 
               ?>
                <p>Pay <?php echo $project['amount']; ?> to enter the pool? Currently <?php echo $project['entries'] . ' of ' $project['max_entries']; ?> have entered</p>
                <?php if (in_array_r($auth_user_id$entries)) { ?>
                    <p>You have Already Joined.</p>
                <?php } else { ?>
                    <button type="submit" class="btn btn-default">Join</button>
                <?php ?>
                <?php
                echo form_close
();
 
               ?>

So it is simply posting it to the project($project_id) method, which checks a permission and if passes submits data to the database.

PHP Code:
   public function enter($project_id) {
 
       if ($this->require_min_level(1)) {
 
           $data = array(
 
               'project_id' => $project_id,
 
               'user_id' => $this->auth_user_id
            
);

 
           $this->load->model('project_model');
 
           $this->pools_model->add_entry($data);
 
           $this->load->view('includes/nav');
 
           $this->load->view('join');
 
           $this->load->view('includes/footer');
 
       } else {
 
           $this->load->view('includes/nav');
 
           $this->load->view('join');
 
           $this->load->view('includes/footer');
 
       }
 
   

The problems I currently have: 


1) How do I prevent someone from just loading the enter($project_id) controller without using the join($project_id) controller?
2) How can I setup error checking? I would rather do this correctly (globally) as I am pretty early in this project and prefer to take my time and do things the right way. I know Codeigniter does basic error checking by default but to what extent? 
3) Anything you would do different to get the same result?

Is anything blatantly wrong with the above that I should kill right now before I get too far in?

Thanks! Looking forward to getting better at OOP and Codeigniter.
Reply


Messages In This Thread
Rather Newish to OOP, Controller question - by BamaStangGuy - 05-19-2016, 07:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB