Welcome Guest, Not a member yet? Register   Sign In
putting html tags in controller
#1

[eluser]Unknown[/eluser]
Is it okay to have some html tags in codeigniter controller. Sometimes i found it difficult to decide that should i move logic into view or html into controller.

Suppose i want to show a textarea for only profile owner and administrator this can be done by two way(as far as i know).
1. Putting more php in view like
Code:
if($this->session->username() == $user || $this->session->username() == $administrator){
echo '<textarea></textarea>';
}

2.Putting html tags in controller like
Code:
$data['textarea'] = ""; if($this->session->username() == $user || $this->session->username() == $administrator){

$data['textarea'] = '<textarea></textarea>';

}

$this->load->view('example', $data);

There are some other many cases where i found it almost impossible or v difficult to have separate html tags from controller like here i want to show menu with submenu also so we have to run two foreach loop one for main menu and the second one for submenu which only run if main menu has submenu.
#2

[eluser]InsiteFX[/eluser]
Code:
$data['textarea'] = $this->build_textarea();

public function build_textarea()
{
    $textarea = '';

    $textarea =. '<textarea>';
    $textarea =. 'This is my TextArea';
    $textarea =. '</textarea>';

    return $textarea
}

You can look at the CI helpers code and see how to do a lot of this, I would build either a helper or a library to build up these method / functions.




Theme © iAndrew 2016 - Forum software by © MyBB