[eluser]simonCI[/eluser]
Hello. I'm about to try to make a simple community, I'm a newbie so bear with me.
This is my current code:
My controller
Code:
public function display_profile($id)
{
$this->load->model('profile_model');
$data['profile'] = $this->profile_model->get_profile_by_id($id);
$data['board'] = $this->profile_model->get_board($id);
$this->load->library('form_validation');
$this->form_validation->set_rules('message', 'Message', 'required|length[3]');
if( $this->form_validation->run() !== false)
{
$data['message'] = $this->input->post('message');
$this->load->model('board_model');
$this->board_model->insert_post($id, $data['message']);
$this->load->view('common/header.php');
$this->load->view('common/nav.php');
$this->load->view('display_profile', $data);
$this->load->view('common/footer.php');
}
else
{
$this->load->view('common/header.php');
$this->load->view('common/nav.php');
$this->load->view('display_profile', $data);
$this->load->view('common/footer.php');
}
}
Model:
Code:
class Board_model extends CI_model
{
//insert post
function insert_post($id, $message){
$q = $this->db->get_where('users', array('id' => $id));
if ($q->num_rows() > 0)
{
$data['account'] = $q->row_array();
}
$data = array(
'author' => $email = $_SESSION['username'],
'board_owner' => $data['account']['email_address'],
'message' => $message
);
$this->db->insert('board_posts', $data);
}
}
view
Code:
<div id="body">
<article>
<header>
<h2 class="inline"><?php echo $profile['email_address'];?> (<?php echo $profile['age'];?>)</h2>
</header>
<a href="<?php echo base_url() . 'images/original/' . $profile['photo_id'];?>" target="_blank"><img id="profile_photo" src="<?php echo base_url() . 'images/thumbs/' . $profile['photo_id'];?>" alt="profile photo"/></a>
<ul>
<li>Age <?php echo $profile['age'];?></li>
<li>Profession <?php echo $profile['profession'];?></li>
<li>Goal <?php echo $profile['goal'];?></li>
</ul>
<p><?php echo $profile['presentation'];?></p>
</article>
<div id="board">
<ul>
<?php
if ($board)
{
//if posts exists
$counter = 1;
foreach($board as $row)
{
echo '<li>';
echo $row->date . ' - ';
echo $row->author . br(1);
echo $row->message . br(2);
echo '</li>';
$counter +=1;
if ($counter == 10) exit;
}
}
?>
</ul>
<!-- insert post-->
<?php
$url = base_url() . substr($_SERVER['REDIRECT_QUERY_STRING'], 1);
echo form_open($url);?>
<p>
<?php echo form_label('', 'message');?>
<?php echo form_textarea('message', '', 'id="message"' );?>
</p>
<p>
<?php echo form_submit('submit', 'Post'); ?>
</p>
<div class="errors"><?php echo validation_errors(); ?></div>
<?php echo form_label();?>
<?php echo form_close();?>
</div><!-- end board -->
</div> <!-- end body -->
So the problem I encountered is that I already have an argument in the controller, called id, which decide which profile to display. If I now want to implement CI pagination class in the board, to display about 10 posts a time. How do I solve the controller with two arguments and the URL?
Thanks in advance /Simon